[PATCH] D128704: [clang-extdef-mapping] Directly process .ast files

2022-06-28 Thread Tobias Hieta via Phabricator via cfe-commits
thieta created this revision.
thieta added reviewers: steakhal, martong, NoQ.
Herald added a subscriber: rnkovacs.
Herald added a project: All.
thieta requested review of this revision.
Herald added a project: clang.

When doing CTU analysis setup you pre-compile .cpp to .ast and then
you run clang-extdef-mapping on the .cpp file as well. This is a
pretty slow process since we have to recompile the file each time.

With this patch you can now run clang-extdef-mapping directly on
the .ast file. That saves a lot of time.

I tried this on llvm/lib/AsmParser/Parser.cpp and running
extdef-mapping on the .cpp file took 5.4s on my machine.

While running it on the .ast file it took 2s.

This can save a lot of time for the setup phase of CTU analysis.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D128704

Files:
  clang/tools/clang-extdef-mapping/ClangExtDefMapGen.cpp

Index: clang/tools/clang-extdef-mapping/ClangExtDefMapGen.cpp
===
--- clang/tools/clang-extdef-mapping/ClangExtDefMapGen.cpp
+++ clang/tools/clang-extdef-mapping/ClangExtDefMapGen.cpp
@@ -1,4 +1,4 @@
-//===- ClangExtDefMapGen.cpp ---===//
+//===- ClangExtDefMapGen.cpp -===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -13,10 +13,12 @@
 
 #include "clang/AST/ASTConsumer.h"
 #include "clang/AST/ASTContext.h"
+#include "clang/Basic/DiagnosticOptions.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/CrossTU/CrossTranslationUnit.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/FrontendActions.h"
+#include "clang/Frontend/TextDiagnosticPrinter.h"
 #include "clang/Tooling/CommonOptionsParser.h"
 #include "clang/Tooling/Tooling.h"
 #include "llvm/Support/CommandLine.h"
@@ -29,12 +31,16 @@
 using namespace clang::cross_tu;
 using namespace clang::tooling;
 
-static cl::OptionCategory ClangExtDefMapGenCategory("clang-extdefmapgen options");
+static cl::OptionCategory
+ClangExtDefMapGenCategory("clang-extdefmapgen options");
 
 class MapExtDefNamesConsumer : public ASTConsumer {
 public:
-  MapExtDefNamesConsumer(ASTContext &Context)
-  : Ctx(Context), SM(Context.getSourceManager()) {}
+  MapExtDefNamesConsumer(ASTContext &Context,
+ StringRef astFilePath = StringRef())
+  : Ctx(Context), SM(Context.getSourceManager()) {
+CurrentFileName = astFilePath.str();
+  }
 
   ~MapExtDefNamesConsumer() {
 // Flush results to standard output.
@@ -111,6 +117,46 @@
 
 static cl::extrahelp CommonHelp(CommonOptionsParser::HelpMessage);
 
+void HandleAST(StringRef astPath) {
+
+  CompilerInstance CI;
+
+  IntrusiveRefCntPtr DiagOpts = new DiagnosticOptions();
+  TextDiagnosticPrinter *DiagClient =
+  new TextDiagnosticPrinter(llvm::errs(), &*DiagOpts);
+  IntrusiveRefCntPtr DiagID(new DiagnosticIDs());
+  IntrusiveRefCntPtr Diags(
+  new DiagnosticsEngine(DiagID, &*DiagOpts, DiagClient));
+
+  std::unique_ptr unit = ASTUnit::LoadFromASTFile(
+  astPath.str(), CI.getPCHContainerOperations()->getRawReader(),
+  ASTUnit::LoadASTOnly, Diags, CI.getFileSystemOpts());
+
+  FileManager fm(CI.getFileSystemOpts());
+  SmallString<128> absPath(astPath);
+  fm.makeAbsolutePath(absPath);
+
+  std::unique_ptr consumer =
+  std::make_unique(unit->getASTContext(), absPath);
+  consumer->HandleTranslationUnit(unit->getASTContext());
+}
+
+void HandleFiles(ArrayRef sourceFiles,
+ CompilationDatabase &compilations) {
+  std::vector sourceToBeParsed;
+  for (StringRef src : sourceFiles) {
+if (src.endswith(".ast"))
+  HandleAST(src);
+else
+  sourceToBeParsed.push_back(src.str());
+  }
+
+  if (!sourceToBeParsed.empty()) {
+ClangTool Tool(compilations, sourceToBeParsed);
+Tool.run(newFrontendActionFactory().get());
+  }
+}
+
 int main(int argc, const char **argv) {
   // Print a stack trace if we signal out.
   sys::PrintStackTraceOnErrorSignal(argv[0], false);
@@ -127,8 +173,6 @@
   }
   CommonOptionsParser &OptionsParser = ExpectedParser.get();
 
-  ClangTool Tool(OptionsParser.getCompilations(),
- OptionsParser.getSourcePathList());
-
-  return Tool.run(newFrontendActionFactory().get());
+  HandleFiles(OptionsParser.getSourcePathList(),
+  OptionsParser.getCompilations());
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D128704: [clang-extdef-mapping] Directly process .ast files

2022-06-28 Thread Tobias Hieta via Phabricator via cfe-commits
thieta added a comment.

This still needs tests - but I wanted to get your early input on the approach 
here and what you all think.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128704

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


[clang] 3f0578d - [clang-cl] Add -emit-ast to clang-cl driver

2022-06-28 Thread Tobias Hieta via cfe-commits

Author: Tobias Hieta
Date: 2022-06-28T09:11:34+02:00
New Revision: 3f0578dd87ee5539eccae507b6a77cfe3354d705

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

LOG: [clang-cl] Add -emit-ast to clang-cl driver

Also make the output of -emit-ast end up where /o points.
The same with .plist files from the static analyzer.

These are changes needed to make it possible to do CTU static
analysing work with clang-cl.

Reviewed By: hans

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

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Driver/Driver.cpp
clang/test/Driver/ast.c
clang/test/Driver/cl-outputs.c

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d379ec8285103..f4fe08aa1a5b3 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1097,7 +1097,7 @@ def dynamiclib : Flag<["-"], "dynamiclib">;
 def dynamic : Flag<["-"], "dynamic">, Flags<[NoArgumentUnused]>;
 def d_Flag : Flag<["-"], "d">, Group;
 def d_Joined : Joined<["-"], "d">, Group;
-def emit_ast : Flag<["-"], "emit-ast">,
+def emit_ast : Flag<["-"], "emit-ast">, Flags<[CoreOption]>,
   HelpText<"Emit Clang AST files for source inputs">;
 def emit_llvm : Flag<["-"], "emit-llvm">, Flags<[CC1Option, FC1Option, 
FlangOption]>, Group,
   HelpText<"Use the LLVM representation for assembler and object files">;

diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index c34da3a67a2e0..0da32dae2ef60 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -5661,6 +5661,14 @@ const char *Driver::GetNamedOutputPath(Compilation &C, 
const JobAction &JA,
 }
   } else if (JA.getType() == types::TY_PCH && IsCLMode()) {
 NamedOutput = C.getArgs().MakeArgString(GetClPchPath(C, BaseName));
+  } else if ((JA.getType() == types::TY_Plist || JA.getType() == 
types::TY_AST) &&
+ C.getArgs().hasArg(options::OPT__SLASH_o)) {
+StringRef Val =
+C.getArgs()
+.getLastArg(options::OPT__SLASH_o)
+->getValue();
+NamedOutput =
+MakeCLOutputFilename(C.getArgs(), Val, BaseName, types::TY_Object);
   } else {
 const char *Suffix = types::getTypeTempSuffix(JA.getType(), IsCLMode());
 assert(Suffix && "All types used for output should have a suffix.");

diff  --git a/clang/test/Driver/ast.c b/clang/test/Driver/ast.c
index c1d7b1a6d7b03..7187454bf90e8 100644
--- a/clang/test/Driver/ast.c
+++ b/clang/test/Driver/ast.c
@@ -25,3 +25,15 @@
 // FIXME: There is a problem with compiling AST's in that the input language is
 // not available for use by other tools (for example, to automatically add
 // -lstdc++). We may need -x [objective-]c++-ast and all that goodness. :(
+
+// Also check clang-cl since the driver is slightly 
diff erent
+// RUN: %clang_cl -ccc-print-phases -emit-ast -- %s 2> %t
+// RUN: echo 'END' >> %t
+// RUN: FileCheck -check-prefix EMIT-AST-PHASES-CLANGCL -input-file %t %s
+
+// EMIT-AST-PHASES-CLANGCL: 0: input,
+// EMIT-AST-PHASES-CLANGCL: , c
+// EMIT-AST-PHASES-CLANGCL: 1: preprocessor, {0}, cpp-output
+// EMIT-AST-PHASES-CLANGCL: 2: compiler, {1}, ast
+// EMIT-AST-PHASES-CLANGCL-NOT: 3:
+// EMIT-AST-PHASES-CLANGCL: END

diff  --git a/clang/test/Driver/cl-outputs.c b/clang/test/Driver/cl-outputs.c
index abca67b12e55e..972e4499dbd9c 100644
--- a/clang/test/Driver/cl-outputs.c
+++ b/clang/test/Driver/cl-outputs.c
@@ -82,6 +82,11 @@
 // RUN: %clang_cl /c /o mydir/ -### -- %s %s 2>&1 | FileCheck 
-check-prefix=CHECK-oMULTIPLESOURCEOK2 %s
 // CHECK-oMULTIPLESOURCEOK2: "-o" "mydir{{[/\\]+}}cl-outputs.obj"
 
+// RUN: %clang_cl -emit-ast /otest.ast -###  -- %s  2>&1 | FileCheck 
-check-prefix=oASTNAME %s
+// oASTNAME:  "-o" "test.ast"
+
+// RUN: %clang_cl --analyze /otest.plist -###  -- %s  2>&1 | FileCheck 
-check-prefix=oPLIST %s
+// oPLIST:  "-o" "test.plist"
 
 // RUN: %clang_cl /c /obar /Fofoo -### -- %s 2>&1 | FileCheck 
-check-prefix=FooRACE1 %s
 // FooRACE1: "-o" "foo.obj"



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


[PATCH] D128409: [clang-cl] Add -emit-ast to clang-cl driver

2022-06-28 Thread Tobias Hieta 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 rG3f0578dd87ee: [clang-cl] Add -emit-ast to clang-cl driver 
(authored by thieta).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128409

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/ast.c
  clang/test/Driver/cl-outputs.c


Index: clang/test/Driver/cl-outputs.c
===
--- clang/test/Driver/cl-outputs.c
+++ clang/test/Driver/cl-outputs.c
@@ -82,6 +82,11 @@
 // RUN: %clang_cl /c /o mydir/ -### -- %s %s 2>&1 | FileCheck 
-check-prefix=CHECK-oMULTIPLESOURCEOK2 %s
 // CHECK-oMULTIPLESOURCEOK2: "-o" "mydir{{[/\\]+}}cl-outputs.obj"
 
+// RUN: %clang_cl -emit-ast /otest.ast -###  -- %s  2>&1 | FileCheck 
-check-prefix=oASTNAME %s
+// oASTNAME:  "-o" "test.ast"
+
+// RUN: %clang_cl --analyze /otest.plist -###  -- %s  2>&1 | FileCheck 
-check-prefix=oPLIST %s
+// oPLIST:  "-o" "test.plist"
 
 // RUN: %clang_cl /c /obar /Fofoo -### -- %s 2>&1 | FileCheck 
-check-prefix=FooRACE1 %s
 // FooRACE1: "-o" "foo.obj"
Index: clang/test/Driver/ast.c
===
--- clang/test/Driver/ast.c
+++ clang/test/Driver/ast.c
@@ -25,3 +25,15 @@
 // FIXME: There is a problem with compiling AST's in that the input language is
 // not available for use by other tools (for example, to automatically add
 // -lstdc++). We may need -x [objective-]c++-ast and all that goodness. :(
+
+// Also check clang-cl since the driver is slightly different
+// RUN: %clang_cl -ccc-print-phases -emit-ast -- %s 2> %t
+// RUN: echo 'END' >> %t
+// RUN: FileCheck -check-prefix EMIT-AST-PHASES-CLANGCL -input-file %t %s
+
+// EMIT-AST-PHASES-CLANGCL: 0: input,
+// EMIT-AST-PHASES-CLANGCL: , c
+// EMIT-AST-PHASES-CLANGCL: 1: preprocessor, {0}, cpp-output
+// EMIT-AST-PHASES-CLANGCL: 2: compiler, {1}, ast
+// EMIT-AST-PHASES-CLANGCL-NOT: 3:
+// EMIT-AST-PHASES-CLANGCL: END
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -5661,6 +5661,14 @@
 }
   } else if (JA.getType() == types::TY_PCH && IsCLMode()) {
 NamedOutput = C.getArgs().MakeArgString(GetClPchPath(C, BaseName));
+  } else if ((JA.getType() == types::TY_Plist || JA.getType() == 
types::TY_AST) &&
+ C.getArgs().hasArg(options::OPT__SLASH_o)) {
+StringRef Val =
+C.getArgs()
+.getLastArg(options::OPT__SLASH_o)
+->getValue();
+NamedOutput =
+MakeCLOutputFilename(C.getArgs(), Val, BaseName, types::TY_Object);
   } else {
 const char *Suffix = types::getTypeTempSuffix(JA.getType(), IsCLMode());
 assert(Suffix && "All types used for output should have a suffix.");
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1097,7 +1097,7 @@
 def dynamic : Flag<["-"], "dynamic">, Flags<[NoArgumentUnused]>;
 def d_Flag : Flag<["-"], "d">, Group;
 def d_Joined : Joined<["-"], "d">, Group;
-def emit_ast : Flag<["-"], "emit-ast">,
+def emit_ast : Flag<["-"], "emit-ast">, Flags<[CoreOption]>,
   HelpText<"Emit Clang AST files for source inputs">;
 def emit_llvm : Flag<["-"], "emit-llvm">, Flags<[CC1Option, FC1Option, 
FlangOption]>, Group,
   HelpText<"Use the LLVM representation for assembler and object files">;


Index: clang/test/Driver/cl-outputs.c
===
--- clang/test/Driver/cl-outputs.c
+++ clang/test/Driver/cl-outputs.c
@@ -82,6 +82,11 @@
 // RUN: %clang_cl /c /o mydir/ -### -- %s %s 2>&1 | FileCheck -check-prefix=CHECK-oMULTIPLESOURCEOK2 %s
 // CHECK-oMULTIPLESOURCEOK2: "-o" "mydir{{[/\\]+}}cl-outputs.obj"
 
+// RUN: %clang_cl -emit-ast /otest.ast -###  -- %s  2>&1 | FileCheck -check-prefix=oASTNAME %s
+// oASTNAME:  "-o" "test.ast"
+
+// RUN: %clang_cl --analyze /otest.plist -###  -- %s  2>&1 | FileCheck -check-prefix=oPLIST %s
+// oPLIST:  "-o" "test.plist"
 
 // RUN: %clang_cl /c /obar /Fofoo -### -- %s 2>&1 | FileCheck -check-prefix=FooRACE1 %s
 // FooRACE1: "-o" "foo.obj"
Index: clang/test/Driver/ast.c
===
--- clang/test/Driver/ast.c
+++ clang/test/Driver/ast.c
@@ -25,3 +25,15 @@
 // FIXME: There is a problem with compiling AST's in that the input language is
 // not available for use by other tools (for example, to automatically add
 // -lstdc++). We may need -x [objective-]c++-ast and all that goodness. :(
+
+// Also check clang-cl since the driver is slightly different
+// RUN: %clang_cl -ccc-print-phases -emit-ast -- %s 2> %t
+// RUN: echo 'END' >> %t
+/

[PATCH] D127873: [clang-format] Fix misplacement of `*` in declaration of pointer to struct

2022-06-28 Thread Jack Huang via Phabricator via cfe-commits
jackhong12 added a comment.

Sorry, I don't have commit access. @HazardyKnusperkeks, could you help me 
commit it?

If I want to contribute to LLVM in the future, how do I get the commit 
permission? Does it depend on the number of patches I submit?


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

https://reviews.llvm.org/D127873

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


[PATCH] D128706: [Clang] Disable clang-format entirely for clang/test tree.

2022-06-28 Thread Martin Böhme via Phabricator via cfe-commits
mboehme created this revision.
Herald added a subscriber: JDevlieghere.
Herald added a project: All.
mboehme requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

See discussion here:

https://github.com/llvm/llvm-project/issues/55982

We don't generally expect test files to be formatted according to the
style guide. Indeed, some tests may require specific formatting for the
purposes of the test.

When tests intentionally do not conform to the "correct" formatting,
this causes errors in the CI, which can drown out real errors and causes
people to stop trusting the CI over time.

>From the history of the clang/test/.clang-format file, it looks as if
there have been attempts to make clang-format do a subset of formatting
that would be useful for tests. However, it looks as if it's hard to
make clang-format do exactly the right thing -- see the back-and-forth
between
13316a7 

and
7b5bddf 
.

Instead, I think the best choice is to entirely disable clang-format on
the clang/test directory.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D128706

Files:
  clang/test/.clang-format


Index: clang/test/.clang-format
===
--- clang/test/.clang-format
+++ clang/test/.clang-format
@@ -1,3 +1 @@
-BasedOnStyle: LLVM
-ColumnLimit: 0
-AlwaysBreakTemplateDeclarations: No
+DisableFormat: true


Index: clang/test/.clang-format
===
--- clang/test/.clang-format
+++ clang/test/.clang-format
@@ -1,3 +1 @@
-BasedOnStyle: LLVM
-ColumnLimit: 0
-AlwaysBreakTemplateDeclarations: No
+DisableFormat: true
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D127293: [clang-tidy] Ignore other members in a union if any member of it is initialized in cppcoreguidelines-pro-type-member-init

2022-06-28 Thread gehry via Phabricator via cfe-commits
Sockke updated this revision to Diff 440517.
Sockke added a comment.

rebased.


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

https://reviews.llvm.org/D127293

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-member-init.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-member-init.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-member-init.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-member-init.cpp
@@ -552,3 +552,19 @@
   int A;
   // CHECK-FIXES-NOT: int A{};
 };
+
+struct S1 {
+  S1() {}
+  union {
+int a = 0;
+int b;
+  };
+};
+
+struct S2 {
+  S2() : a{} {}
+  union {
+int a;
+int b;
+  };
+};
Index: clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
===
--- clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
+++ clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
@@ -61,6 +61,17 @@
   }
 }
 
+void removeFieldInitialized(const FieldDecl *M,
+SmallPtrSetImpl &FieldDecls) {
+  const RecordDecl *R = M->getParent();
+  if (R && R->isUnion()) {
+// Erase all members in a union if any member of it is initialized.
+for (const auto *F : R->fields())
+  FieldDecls.erase(F);
+  } else
+FieldDecls.erase(M);
+}
+
 void removeFieldsInitializedInBody(
 const Stmt &Stmt, ASTContext &Context,
 SmallPtrSetImpl &FieldDecls) {
@@ -70,7 +81,7 @@
 hasLHS(memberExpr(member(fieldDecl().bind("fieldDecl")),
 Stmt, Context);
   for (const auto &Match : Matches)
-FieldDecls.erase(Match.getNodeAs("fieldDecl"));
+removeFieldInitialized(Match.getNodeAs("fieldDecl"), 
FieldDecls);
 }
 
 StringRef getName(const FieldDecl *Field) { return Field->getName(); }
@@ -418,13 +429,18 @@
 
   // Gather all fields (direct and indirect) that need to be initialized.
   SmallPtrSet FieldsToInit;
-  forEachField(ClassDecl, ClassDecl.fields(), [&](const FieldDecl *F) {
+  bool AnyMemberHasInitPerUnion = false;
+  forEachFieldWithFilter(ClassDecl, ClassDecl.fields(),
+ AnyMemberHasInitPerUnion, [&](const FieldDecl *F) {
 if (IgnoreArrays && F->getType()->isArrayType())
   return;
+if (F->hasInClassInitializer() && F->getParent()->isUnion())
+  AnyMemberHasInitPerUnion = true;
 if (!F->hasInClassInitializer() &&
 utils::type_traits::isTriviallyDefaultConstructible(F->getType(),
 Context) &&
-!isEmpty(Context, F->getType()) && !F->isUnnamedBitfield())
+!isEmpty(Context, F->getType()) && !F->isUnnamedBitfield() &&
+!AnyMemberHasInitPerUnion)
   FieldsToInit.insert(F);
   });
   if (FieldsToInit.empty())
@@ -437,7 +453,7 @@
   if (Init->isAnyMemberInitializer() && Init->isWritten()) {
 if (IsUnion)
   return; // We can only initialize one member of a union.
-FieldsToInit.erase(Init->getAnyMember());
+removeFieldInitialized(Init->getAnyMember(), FieldsToInit);
   }
 }
 removeFieldsInitializedInBody(*Ctor->getBody(), Context, FieldsToInit);
@@ -478,7 +494,7 @@
   // Collect all fields but only suggest a fix for the first member of unions,
   // as initializing more than one union member is an error.
   SmallPtrSet FieldsToFix;
-  bool AnyMemberHasInitPerUnion = false;
+  AnyMemberHasInitPerUnion = false;
   forEachFieldWithFilter(ClassDecl, ClassDecl.fields(),
  AnyMemberHasInitPerUnion, [&](const FieldDecl *F) {
 if (!FieldsToInit.count(F))


Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-member-init.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-member-init.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-member-init.cpp
@@ -552,3 +552,19 @@
   int A;
   // CHECK-FIXES-NOT: int A{};
 };
+
+struct S1 {
+  S1() {}
+  union {
+int a = 0;
+int b;
+  };
+};
+
+struct S2 {
+  S2() : a{} {}
+  union {
+int a;
+int b;
+  };
+};
Index: clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
===
--- clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
+++ clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
@@ -61,6 +61,17 @@
   }
 }
 
+void removeFieldInitialized(const FieldDecl *M,
+SmallPtrSetImpl &FieldDecls) {
+  const RecordDecl *R = M->getParent();
+  if (R && R->isUnion()) {
+// Erase all memb

[PATCH] D128708: [pseudo] Simplify/loosen the grammar around lambda captures.

2022-06-28 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added a reviewer: hokein.
Herald added a project: All.
sammccall requested review of this revision.
Herald added subscribers: cfe-commits, alextsao1999.
Herald added a project: clang-tools-extra.

Treat captures as a uniform list, rather than default-captures being special
snowflakes that may only appear at the start.

This accepts a larger set of (incorrect) code, and simplifies error-handling
by making this fit into the usual homogeneous-list pattern.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D128708

Files:
  clang-tools-extra/pseudo/lib/cxx.bnf
  clang-tools-extra/pseudo/test/cxx/capture-list.cpp


Index: clang-tools-extra/pseudo/test/cxx/capture-list.cpp
===
--- /dev/null
+++ clang-tools-extra/pseudo/test/cxx/capture-list.cpp
@@ -0,0 +1,23 @@
+// RUN: clang-pseudo -grammar=%cxx-bnf-file -source=%s --print-forest | 
FileCheck %s
+// We loosely allow capture defaults in any position/multiple times.
+auto lambda = [&, &foo, bar(x), =]{};
+// CHECK:  lambda-introducer := [ capture-list ]
+// CHECK-NEXT: ├─[
+// CHECK-NEXT: ├─capture-list
+// CHECK-NEXT: │ ├─capture-list
+// CHECK-NEXT: │ │ ├─capture-list
+// CHECK-NEXT: │ │ │ ├─capture-list~& := tok[4]
+// CHECK-NEXT: │ │ │ ├─,
+// CHECK-NEXT: │ │ │ └─capture~simple-capture
+// CHECK-NEXT: │ │ │   ├─&
+// CHECK-NEXT: │ │ │   └─IDENTIFIER := tok[7]
+// CHECK-NEXT: │ │ ├─,
+// CHECK-NEXT: │ │ └─capture~init-capture
+// CHECK-NEXT: │ │   ├─IDENTIFIER := tok[9]
+// CHECK-NEXT: │ │   └─initializer := ( expression-list )
+// CHECK-NEXT: │ │ ├─(
+// CHECK-NEXT: │ │ ├─expression-list~IDENTIFIER := tok[11]
+// CHECK-NEXT: │ │ └─)
+// CHECK-NEXT: │ ├─,
+// CHECK-NEXT: │ └─capture~=
+// CHECK-NEXT: └─]
Index: clang-tools-extra/pseudo/lib/cxx.bnf
===
--- clang-tools-extra/pseudo/lib/cxx.bnf
+++ clang-tools-extra/pseudo/lib/cxx.bnf
@@ -76,17 +76,17 @@
 nested-name-specifier := nested-name-specifier TEMPLATE_opt simple-template-id 
::
 lambda-expression := lambda-introducer lambda-declarator_opt compound-statement
 lambda-expression := lambda-introducer < template-parameter-list > 
requires-clause_opt lambda-declarator_opt compound-statement
-lambda-introducer := [ lambda-capture_opt ]
+#! We allow a capture-default to appear anywhere in a capture-list.
+# This simplifies the grammar and error recovery.
+lambda-introducer := [ capture-list_opt ]
 lambda-declarator := ( parameter-declaration-clause_opt ) 
decl-specifier-seq_opt noexcept-specifier_opt trailing-return-type_opt 
requires-clause_opt
-lambda-capture := capture-default
-lambda-capture := capture-list
-lambda-capture := capture-default , capture-list
-capture-default := &
-capture-default := =
 capture-list := capture
 capture-list := capture-list , capture
+capture := capture-default
 capture := simple-capture
 capture := init-capture
+capture-default := &
+capture-default := =
 simple-capture := IDENTIFIER ..._opt
 simple-capture := & IDENTIFIER ..._opt
 simple-capture := THIS


Index: clang-tools-extra/pseudo/test/cxx/capture-list.cpp
===
--- /dev/null
+++ clang-tools-extra/pseudo/test/cxx/capture-list.cpp
@@ -0,0 +1,23 @@
+// RUN: clang-pseudo -grammar=%cxx-bnf-file -source=%s --print-forest | FileCheck %s
+// We loosely allow capture defaults in any position/multiple times.
+auto lambda = [&, &foo, bar(x), =]{};
+// CHECK:  lambda-introducer := [ capture-list ]
+// CHECK-NEXT: ├─[
+// CHECK-NEXT: ├─capture-list
+// CHECK-NEXT: │ ├─capture-list
+// CHECK-NEXT: │ │ ├─capture-list
+// CHECK-NEXT: │ │ │ ├─capture-list~& := tok[4]
+// CHECK-NEXT: │ │ │ ├─,
+// CHECK-NEXT: │ │ │ └─capture~simple-capture
+// CHECK-NEXT: │ │ │   ├─&
+// CHECK-NEXT: │ │ │   └─IDENTIFIER := tok[7]
+// CHECK-NEXT: │ │ ├─,
+// CHECK-NEXT: │ │ └─capture~init-capture
+// CHECK-NEXT: │ │   ├─IDENTIFIER := tok[9]
+// CHECK-NEXT: │ │   └─initializer := ( expression-list )
+// CHECK-NEXT: │ │ ├─(
+// CHECK-NEXT: │ │ ├─expression-list~IDENTIFIER := tok[11]
+// CHECK-NEXT: │ │ └─)
+// CHECK-NEXT: │ ├─,
+// CHECK-NEXT: │ └─capture~=
+// CHECK-NEXT: └─]
Index: clang-tools-extra/pseudo/lib/cxx.bnf
===
--- clang-tools-extra/pseudo/lib/cxx.bnf
+++ clang-tools-extra/pseudo/lib/cxx.bnf
@@ -76,17 +76,17 @@
 nested-name-specifier := nested-name-specifier TEMPLATE_opt simple-template-id ::
 lambda-expression := lambda-introducer lambda-declarator_opt compound-statement
 lambda-expression := lambda-introducer < template-parameter-list > requires-clause_opt lambda-declarator_opt compound-statement
-lambda-introducer := [ lambda-capture_opt ]
+#! We allow a capture

[PATCH] D124690: [clangd] add inlay hints for std::forward-ed parameter packs

2022-06-28 Thread Tobias Ribizel via Phabricator via cfe-commits
upsj added a comment.

can you give this another look, if you have some time @sammccall?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124690

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


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

2022-06-28 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a comment.

Thanks for the update!

In D127082#3606746 , @daiyousei-qz 
wrote:

> Therefore, I still put definition in front of the expansion in this update.
>
> Regarding to the size limit of expansion:
> Here I'm using a 2048 bytes buffer.

I think these are reasonable choices to start with. We can always tweak them 
after the fact if we'd like.




Comment at: clang-tools-extra/clangd/Hover.cpp:676
+  auto Expansion = AST.getTokens().expansionStartingAt(&Tok);
+  if (Expansion) {
+// Use a fixed size buffer for better performance and presentation.

nit: these two lines can be combined as:

```
if (auto Expansion = AST.getTokens().expansionStartingAt(&Tok)) {
   ...
}
```



Comment at: clang-tools-extra/clangd/Hover.cpp:1091
+
+  // Reformat Macro Expansion
+  if (!HI->MacroExpansion.empty()) {

It would be interesting to have a couple of test cases that exercise the 
reformatting in non-trivial ways, e.g. long expansions that need to be wrapped 
onto multiple lines

I would suggest two such test cases, one with the expansion being in a 
declaration context, and the second an expression context (for this one, to 
make it long enough, the expansion could contain e.g. an `a ? b : c` expression)

(I'm suggesting the expression-context testcase in part as a sanity check to 
make sure that `format::reformat()` handles such code reasonably in the first 
place)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127082

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


[PATCH] D128709: [clang-format] Handle Verilog attributes

2022-06-28 Thread sstwcw via Phabricator via cfe-commits
sstwcw created this revision.
sstwcw added reviewers: HazardyKnusperkeks, MyDeveloperDay, curdeius, owenpan.
Herald added a project: All.
sstwcw requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D128709

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/FormatTestVerilog.cpp


Index: clang/unittests/Format/FormatTestVerilog.cpp
===
--- clang/unittests/Format/FormatTestVerilog.cpp
+++ clang/unittests/Format/FormatTestVerilog.cpp
@@ -71,6 +71,12 @@
 TEST_F(FormatTestVerilog, If) {
   verifyFormat("if (x)\n"
"  x = x;");
+  verifyFormat("unique if (x)\n"
+   "  x = x;");
+  verifyFormat("unique0 if (x)\n"
+   "  x = x;");
+  verifyFormat("priority if (x)\n"
+   "  x = x;");
   verifyFormat("if (x)\n"
"  x = x;\n"
"x = x;");
@@ -137,6 +143,14 @@
"  x = {x};\n"
"else\n"
"  {x} = {x};");
+
+  // With attributes.
+  verifyFormat("(* x *) if (x)\n"
+   "  x = x;");
+  verifyFormat("(* x = \"x\" *) if (x)\n"
+   "  x = x;");
+  verifyFormat("(* x, x = \"x\" *) if (x)\n"
+   "  x = x;");
 }
 
 TEST_F(FormatTestVerilog, Preprocessor) {
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1456,6 +1456,26 @@
 addUnwrappedLine();
 return;
   }
+
+  if (Style.isVerilog()) {
+// Skip things that can exist before keywords like 'if' and 'case'.
+while (true) {
+  if (FormatTok->isOneOf(Keywords.kw_priority, Keywords.kw_unique,
+ Keywords.kw_unique0)) {
+nextToken();
+  } else if (FormatTok->is(tok::l_paren)) {
+const FormatToken *Next = Tokens->peekNextToken();
+if (Next && Next->is(tok::star))
+  parseParens();
+else
+  break;
+  } else {
+break;
+  }
+}
+  }
+
+  // Tokens that only make sense at the beginning of a line.
   switch (FormatTok->Tok.getKind()) {
   case tok::kw_asm:
 nextToken();
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3957,6 +3957,9 @@
   Left.MatchingParen->endsSequence(tok::l_paren, tok::at {
   return true;
 }
+// Add space in attribute like `(* ASYNC_REG = "TRUE" *)`.
+if (Left.endsSequence(tok::star, tok::l_paren) && 
Right.is(tok::identifier))
+  return true;
   }
   if (Left.is(TT_ImplicitStringLiteral))
 return Right.hasWhitespaceBefore();


Index: clang/unittests/Format/FormatTestVerilog.cpp
===
--- clang/unittests/Format/FormatTestVerilog.cpp
+++ clang/unittests/Format/FormatTestVerilog.cpp
@@ -71,6 +71,12 @@
 TEST_F(FormatTestVerilog, If) {
   verifyFormat("if (x)\n"
"  x = x;");
+  verifyFormat("unique if (x)\n"
+   "  x = x;");
+  verifyFormat("unique0 if (x)\n"
+   "  x = x;");
+  verifyFormat("priority if (x)\n"
+   "  x = x;");
   verifyFormat("if (x)\n"
"  x = x;\n"
"x = x;");
@@ -137,6 +143,14 @@
"  x = {x};\n"
"else\n"
"  {x} = {x};");
+
+  // With attributes.
+  verifyFormat("(* x *) if (x)\n"
+   "  x = x;");
+  verifyFormat("(* x = \"x\" *) if (x)\n"
+   "  x = x;");
+  verifyFormat("(* x, x = \"x\" *) if (x)\n"
+   "  x = x;");
 }
 
 TEST_F(FormatTestVerilog, Preprocessor) {
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1456,6 +1456,26 @@
 addUnwrappedLine();
 return;
   }
+
+  if (Style.isVerilog()) {
+// Skip things that can exist before keywords like 'if' and 'case'.
+while (true) {
+  if (FormatTok->isOneOf(Keywords.kw_priority, Keywords.kw_unique,
+ Keywords.kw_unique0)) {
+nextToken();
+  } else if (FormatTok->is(tok::l_paren)) {
+const FormatToken *Next = Tokens->peekNextToken();
+if (Next && Next->is(tok::star))
+  parseParens();
+else
+  break;
+  } else {
+break;
+  }
+}
+  }
+
+  // Tokens that only make sense at the beginning of a line.
   switch (FormatTok->Tok.getKind()) {
   case tok::kw_asm:
 nextToken();
Index: clang/lib/Format/TokenAnnotator.cpp
=

[PATCH] D128711: [clang-format] Handle Verilog blocks

2022-06-28 Thread sstwcw via Phabricator via cfe-commits
sstwcw created this revision.
sstwcw added reviewers: HazardyKnusperkeks, MyDeveloperDay, curdeius, owenpan.
Herald added a project: All.
sstwcw requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Now stuff inside begin-end blocks get indented.

Some tests are moved into FormatTestVerilog.Block from
FormatTestVerilog.If because they have nothing to do with if statements.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D128711

Files:
  clang/lib/Format/FormatToken.h
  clang/lib/Format/TokenAnnotator.cpp
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/FormatTestVerilog.cpp
  clang/unittests/Format/TokenAnnotatorTest.cpp

Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -862,6 +862,12 @@
   ASSERT_EQ(Tokens.size(), 7u) << Tokens;
   EXPECT_TOKEN(Tokens[2], tok::tilde, TT_UnaryOperator);
   EXPECT_TOKEN(Tokens[3], tok::pipe, TT_UnaryOperator);
+  // Test for block label colons.
+  Tokens = Annotate("begin : x\n"
+"end : x");
+  ASSERT_EQ(Tokens.size(), 7u);
+  EXPECT_TOKEN(Tokens[1], tok::colon, TT_VerilogBlockLabelColon);
+  EXPECT_TOKEN(Tokens[4], tok::colon, TT_VerilogBlockLabelColon);
 }
 
 } // namespace
Index: clang/unittests/Format/FormatTestVerilog.cpp
===
--- clang/unittests/Format/FormatTestVerilog.cpp
+++ clang/unittests/Format/FormatTestVerilog.cpp
@@ -66,6 +66,56 @@
   verifyFormat("x = 16'sd?;");
 }
 
+TEST_F(FormatTestVerilog, Block) {
+  verifyFormat("begin\n"
+   "  x = x;\n"
+   "end");
+  verifyFormat("begin : x\n"
+   "  x = x;\n"
+   "end : x");
+  verifyFormat("begin\n"
+   "  x = x;\n"
+   "  x = x;\n"
+   "end");
+  verifyFormat("fork\n"
+   "  x = x;\n"
+   "join");
+  verifyFormat("fork\n"
+   "  x = x;\n"
+   "join_any");
+  verifyFormat("fork\n"
+   "  x = x;\n"
+   "join_none");
+  verifyFormat("generate\n"
+   "  x = x;\n"
+   "endgenerate");
+  verifyFormat("generate : x\n"
+   "  x = x;\n"
+   "endgenerate : x");
+  // Nested blocks.
+  verifyFormat("begin\n"
+   "  begin\n"
+   "  end\n"
+   "end");
+  verifyFormat("begin : x\n"
+   "  begin\n"
+   "  end\n"
+   "end : x");
+  verifyFormat("begin : x\n"
+   "  begin : x\n"
+   "  end : x\n"
+   "end : x");
+  verifyFormat("begin\n"
+   "  begin : x\n"
+   "  end : x\n"
+   "end");
+  // Test that 'disable fork' and 'rand join' don't get mistaken as blocks.
+  verifyFormat("disable fork;\n"
+   "x = x;");
+  verifyFormat("rand join x x;\n"
+   "x = x;");
+}
+
 TEST_F(FormatTestVerilog, Delay) {
   // Delay by the default unit.
   verifyFormat("#0;");
@@ -129,10 +179,6 @@
"  x = x;\n"
"  x = x;\n"
"end");
-  verifyFormat("disable fork;\n"
-   "x = x;");
-  verifyFormat("rand join x x;\n"
-   "x = x;");
   verifyFormat("if (x) fork\n"
"  x = x;\n"
"join");
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1887,6 +1887,14 @@
 return;
   }
 
+  if (Style.isVerilog()) {
+if (Keywords.isVerilogBegin(*FormatTok)) {
+  parseBlock();
+  addUnwrappedLine();
+  return;
+}
+  }
+
   if (FormatTok->is(Keywords.kw_interface)) {
 if (parseStructLike())
   return;
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -947,6 +947,12 @@
   Tok->setType(TT_CSharpNamedArgumentColon);
   break;
 }
+  } else if (Style.isVerilog() && Tok->isNot(TT_BinaryOperator)) {
+if (Keywords.isVerilogEnd(*Tok->Previous) ||
+Keywords.isVerilogBegin(*Tok->Previous)) {
+  Tok->setType(TT_VerilogBlockLabelColon);
+}
+break;
   }
   if (Line.First->isOneOf(Keywords.kw_module, Keywords.kw_import) ||
   Line.First->startsSequence(tok::kw_export, Keywords.kw_module) ||
Index: clang/lib/Format/FormatToken.h
===
--- clang/lib/Format/FormatToken.h
+++ clang/lib/Format/FormatToken.h
@@ -135,6 +135,8 @@
   TYPE(UnaryOperator)

[PATCH] D128712: [clang-format] Handle Verilog modules

2022-06-28 Thread sstwcw via Phabricator via cfe-commits
sstwcw created this revision.
sstwcw added reviewers: HazardyKnusperkeks, MyDeveloperDay, curdeius, owenpan.
Herald added a project: All.
sstwcw requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Now things inside hierarchies like modules and interfaces are
indented.  When the module header spans multiple lines, all except the
first line are indented as continuations.  We added the property
`IsContinuation` to mark lines that should be indented this way.

In order that the colons inside square brackets don't get labeled as
`TT_ObjCMethodExpr`, we added a check to only use this type when the
language is C#.  We used `isCpp` which returns true for C# and also when
the filename is not given and the program isn't sure what language it is
handling.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D128712

Files:
  clang/lib/Format/FormatToken.h
  clang/lib/Format/TokenAnnotator.cpp
  clang/lib/Format/TokenAnnotator.h
  clang/lib/Format/UnwrappedLineFormatter.cpp
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/lib/Format/UnwrappedLineParser.h
  clang/unittests/Format/FormatTestVerilog.cpp
  clang/unittests/Format/TokenAnnotatorTest.cpp

Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -868,6 +868,13 @@
   ASSERT_EQ(Tokens.size(), 7u);
   EXPECT_TOKEN(Tokens[1], tok::colon, TT_VerilogBlockLabelColon);
   EXPECT_TOKEN(Tokens[4], tok::colon, TT_VerilogBlockLabelColon);
+  // Test that the dimension colon is annotated correctly.
+  Tokens = Annotate("var [1 : 0] x;");
+  ASSERT_EQ(Tokens.size(), 9u) << Tokens;
+  EXPECT_TOKEN(Tokens[3], tok::colon, TT_BitFieldColon);
+  Tokens = Annotate("extern function [1 : 0] x;");
+  ASSERT_EQ(Tokens.size(), 10u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::colon, TT_BitFieldColon);
 }
 
 } // namespace
Index: clang/unittests/Format/FormatTestVerilog.cpp
===
--- clang/unittests/Format/FormatTestVerilog.cpp
+++ clang/unittests/Format/FormatTestVerilog.cpp
@@ -139,6 +139,75 @@
 "x = x;"));
 }
 
+TEST_F(FormatTestVerilog, Hierarchy) {
+  verifyFormat("module x;\n"
+   "endmodule");
+  // Test that the end label is on the same line as the end keyword.
+  verifyFormat("module x;\n"
+   "endmodule : x");
+  // Test that things inside are indented.
+  verifyFormat("module x;\n"
+   "  generate\n"
+   "  endgenerate\n"
+   "endmodule");
+  verifyFormat("program x;\n"
+   "  generate\n"
+   "  endgenerate\n"
+   "endprogram");
+  verifyFormat("interface x;\n"
+   "  generate\n"
+   "  endgenerate\n"
+   "endinterface");
+  verifyFormat("task x;\n"
+   "  generate\n"
+   "  endgenerate\n"
+   "endtask");
+  verifyFormat("function x;\n"
+   "  generate\n"
+   "  endgenerate\n"
+   "endfunction");
+  verifyFormat("class x;\n"
+   "  generate\n"
+   "  endgenerate\n"
+   "endclass");
+  // Test that they nest.
+  verifyFormat("module x;\n"
+   "  program x;\n"
+   "program x;\n"
+   "endprogram\n"
+   "  endprogram\n"
+   "endmodule");
+  // Test that an extern declaration doesn't change the indentation.
+  verifyFormat("extern module x;\n"
+   "x = x;");
+  // Test complex headers
+  verifyFormat("extern module x\n"
+   "import x.x::x::*;\n"
+   "import x;\n"
+   "#(parameter x)\n"
+   "(output x);");
+  verifyFormat("module x\n"
+   "import x.x::x::*;\n"
+   "import x;\n"
+   "#(parameter x)\n"
+   "(output x);\n"
+   "  generate\n"
+   "  endgenerate\n"
+   "endmodule : x");
+  verifyFormat("virtual class x\n"
+   "(x)\n"
+   "extends x(x)\n"
+   "implements x, x, x;\n"
+   "  generate\n"
+   "  endgenerate\n"
+   "endclass : x\n");
+  verifyFormat("function automatic logic [1 : 0] x\n"
+   "(input x);\n"
+   "  generate\n"
+   "  endgenerate\n"
+   "endfunction : x");
+}
+
 TEST_F(FormatTestVerilog, If) {
   verifyFormat("if (x)\n"
"  x = x;");
Index: clang/lib/Format/UnwrappedLineParser.h
===
--- clang/lib/Format/UnwrappedLineParser.h
+++ clang/lib/Format/UnwrappedLineParser.h
@@ -48,6 +48,10 @@
 
   bool MustBeDeclaration;
 
+  /// \c True if this line should b

[PATCH] D128713: [clang-format] Handle Verilog user-defined primitives

2022-06-28 Thread sstwcw via Phabricator via cfe-commits
sstwcw created this revision.
sstwcw added reviewers: HazardyKnusperkeks, MyDeveloperDay, curdeius, owenpan.
Herald added a project: All.
sstwcw requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D128713

Files:
  clang/lib/Format/FormatToken.h
  clang/lib/Format/TokenAnnotator.cpp
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/lib/Format/UnwrappedLineParser.h
  clang/unittests/Format/FormatTestVerilog.cpp

Index: clang/unittests/Format/FormatTestVerilog.cpp
===
--- clang/unittests/Format/FormatTestVerilog.cpp
+++ clang/unittests/Format/FormatTestVerilog.cpp
@@ -441,5 +441,46 @@
   }
 }
 
+TEST_F(FormatTestVerilog, Primitive) {
+  verifyFormat("primitive multiplexer\n"
+   "(mux, control, dataA, dataB);\n"
+   "  output mux;\n"
+   "  input control, dataA, dataB;\n"
+   "  table\n"
+   "0 1 ? : 1;\n"
+   "0 0 ? : 0;\n"
+   "1 ? 1 : 1;\n"
+   "1 ? 0 : 0;\n"
+   "x 0 0 : 0;\n"
+   "x 1 1 : 1;\n"
+   "  endtable\n"
+   "endprimitive");
+  verifyFormat("primitive latch\n"
+   "(q, ena_, data);\n"
+   "  output q;\n"
+   "  reg q;\n"
+   "  input ena_, data;\n"
+   "  table\n"
+   "0 1 : ? : 1;\n"
+   "0 0 : ? : 0;\n"
+   "1 ? : ? : -;\n"
+   "? * : ? : -;\n"
+   "  endtable\n"
+   "endprimitive");
+  verifyFormat("primitive d\n"
+   "(q, clock, data);\n"
+   "  output q;\n"
+   "  reg q;\n"
+   "  input clock, data;\n"
+   "  table\n"
+   "(01) 0 : ? : 0;\n"
+   "(01) 1 : ? : 1;\n"
+   "(0?) 1 : 1 : 1;\n"
+   "(0?) 0 : 0 : 0;\n"
+   "(?0) ? : ? : -;\n"
+   "(?\?) ? : ? : -;\n"
+   "  endtable\n"
+   "endprimitive");
+}
 } // namespace format
 } // end namespace clang
Index: clang/lib/Format/UnwrappedLineParser.h
===
--- clang/lib/Format/UnwrappedLineParser.h
+++ clang/lib/Format/UnwrappedLineParser.h
@@ -182,6 +182,7 @@
   // Returns the number of levels of indentation in addition to the normal 1
   // level for a block, used for indenting case labels.
   unsigned parseVerilogHierHeader();
+  void parseVerilogTable();
 
   // Used by addUnwrappedLine to denote whether to keep or remove a level
   // when resetting the line state.
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1912,6 +1912,10 @@
   }
 
   if (Style.isVerilog()) {
+if (FormatTok->is(Keywords.kw_table)) {
+  parseVerilogTable();
+  return;
+}
 if (Keywords.isVerilogBegin(*FormatTok) ||
 Keywords.isVerilogHier(*FormatTok)) {
   parseBlock();
@@ -4153,6 +4157,25 @@
   return AddLevels;
 }
 
+void UnwrappedLineParser::parseVerilogTable() {
+  assert(FormatTok->is(Keywords.kw_table));
+  nextToken(/*LevelDifference=*/1);
+  addUnwrappedLine();
+
+  unsigned InitialLevel = Line->Level++;
+  while (!eof() && !Keywords.isVerilogEnd(*FormatTok)) {
+FormatToken *Tok = FormatTok;
+nextToken();
+if (Tok->is(tok::semi))
+  addUnwrappedLine();
+else if (Tok->isOneOf(tok::star, tok::colon, tok::question, tok::minus))
+  Tok->setFinalizedType(TT_VerilogTableItem);
+  }
+  Line->Level = InitialLevel;
+  nextToken(/*LevelDifference=*/-1);
+  addUnwrappedLine();
+}
+
 LLVM_ATTRIBUTE_UNUSED static void printDebugInfo(const UnwrappedLine &Line,
  StringRef Prefix = "") {
   llvm::dbgs() << Prefix << "Line(" << Line.Level
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -917,6 +917,10 @@
   bool consumeToken() {
 FormatToken *Tok = CurrentToken;
 next();
+// In Verilog primitives' state tables, `:`, `?`, and `-` aren't normal
+// operators.
+if (Tok->is(TT_VerilogTableItem))
+  return true;
 switch (Tok->Tok.getKind()) {
 case tok::plus:
 case tok::minus:
@@ -3957,6 +3961,14 @@
   return true;
 }
   } else if (Style.isVerilog()) {
+// Add space between things in a primitive's state table unless in a
+// transition like `(0?)`.
+if ((Left.is(TT_VerilogTableItem) &&
+ !Right.isOneOf(tok::r_paren, tok::semi)) ||
+(

[PATCH] D128714: [clang-format] Handle Verilog case statements

2022-06-28 Thread sstwcw via Phabricator via cfe-commits
sstwcw created this revision.
sstwcw added reviewers: HazardyKnusperkeks, MyDeveloperDay, curdeius, owenpan.
Herald added a project: All.
sstwcw requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

These statements are like switch statements in C, but without the 'case'
keyword in labels.

How labels are parsed.  In UnwrappedLineParser, the program tries to
parse a statement every time it sees a colon.  In TokenAnnotator, a
colon that isn't part of an expression is annotated as a label.

The token type `TT_GotoLabelColon` is added.  We did not include Verilog
in the name because we thought we would eventually have to fix the
problem that case labels in C can't contain ternary conditional
expressions and we would use that token type.

The style is like below.  Labels are on separate lines and indented by
default.  The linked style guide also has examples where labels and the
corresponding statements are on the same lines.  They are not supported
for now.

https://github.com/lowRISC/style-guides/blob/master/VerilogCodingStyle.md

  case (state_q)
StIdle:
  state_d = StA;
StA: begin
  state_d = StB;
end
  endcase


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D128714

Files:
  clang/lib/Format/ContinuationIndenter.cpp
  clang/lib/Format/Format.cpp
  clang/lib/Format/FormatToken.h
  clang/lib/Format/TokenAnnotator.cpp
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/lib/Format/UnwrappedLineParser.h
  clang/unittests/Format/FormatTestVerilog.cpp
  clang/unittests/Format/TokenAnnotatorTest.cpp

Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -875,6 +875,21 @@
   Tokens = Annotate("extern function [1 : 0] x;");
   ASSERT_EQ(Tokens.size(), 10u) << Tokens;
   EXPECT_TOKEN(Tokens[4], tok::colon, TT_BitFieldColon);
+  // Test case labels and ternary operators.
+  Tokens = Annotate("case (x)\n"
+"  x:\n"
+"x;\n"
+"endcase\n");
+  ASSERT_EQ(Tokens.size(), 10u) << Tokens;
+  EXPECT_TOKEN(Tokens[5], tok::colon, TT_GotoLabelColon);
+  Tokens = Annotate("case (x)\n"
+"  x ? x : x:\n"
+"x;\n"
+"endcase\n");
+  ASSERT_EQ(Tokens.size(), 14u) << Tokens;
+  EXPECT_TOKEN(Tokens[5], tok::question, TT_ConditionalExpr);
+  EXPECT_TOKEN(Tokens[7], tok::colon, TT_ConditionalExpr);
+  EXPECT_TOKEN(Tokens[9], tok::colon, TT_GotoLabelColon);
 }
 
 } // namespace
Index: clang/unittests/Format/FormatTestVerilog.cpp
===
--- clang/unittests/Format/FormatTestVerilog.cpp
+++ clang/unittests/Format/FormatTestVerilog.cpp
@@ -116,6 +116,90 @@
"x = x;");
 }
 
+TEST_F(FormatTestVerilog, Case) {
+  verifyFormat("case (data)\n"
+   "endcase");
+  verifyFormat("casex (data)\n"
+   "endcase");
+  verifyFormat("casez (data)\n"
+   "endcase");
+  verifyFormat("case (data) inside\n"
+   "endcase");
+  verifyFormat("case (data)\n"
+   "  16'd0:\n"
+   "result = 10'b01;\n"
+   "endcase");
+  verifyFormat("case (data)\n"
+   "  :\n"
+   "result = 10'b01;\n"
+   "endcase");
+  // Test labels with multiple options.
+  verifyFormat("case (data)\n"
+   "  16'd0, 16'd1:\n"
+   "result = 10'b01;\n"
+   "endcase");
+  verifyFormat("case (data)\n"
+   "  16'd0, //\n"
+   "  16'd1:\n"
+   "result = 10'b01;\n"
+   "endcase");
+  // Test that blocks following labels are indented.
+  verifyFormat("case (data)\n"
+   "  16'd1: fork\n"
+   "result = 10'b10;\n"
+   "  join\n"
+   "endcase\n");
+  verifyFormat("case (data)\n"
+   "  16'd1: fork : x\n"
+   "result = 10'b10;\n"
+   "  join : x\n"
+   "endcase\n");
+  // Test default.
+  verifyFormat("case (data)\n"
+   "  default\n"
+   "result = 10'b10;\n"
+   "endcase");
+  verifyFormat("case (data)\n"
+   "  default:\n"
+   "result = 10'b10;\n"
+   "endcase");
+  // Test that question marks and colons don't get mistaken as labels.
+  verifyFormat("case (data)\n"
+   "  8'b1???:\n"
+   "instruction1(ir);\n"
+   "endcase");
+  verifyFormat("case (data)\n"
+   "  x ? 8'b1??? : 1:\n"
+   "instruction3(ir);\n"
+   "endcase");
+  // Test indention options.
+  auto Style = getLLVMStyle(FormatStyle::LK_

[PATCH] D128715: [clang-tidy] Fix confusable identifiers interaction with DeclContext

2022-06-28 Thread serge via Phabricator via cfe-commits
serge-sans-paille created this revision.
serge-sans-paille added a reviewer: aaron.ballman.
Herald added subscribers: carlosgalvezp, xazax.hun.
Herald added a project: All.
serge-sans-paille requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Properly checks enclosing DeclContext, and add the related test case.

Fix #56221


https://reviews.llvm.org/D128715

Files:
  clang-tools-extra/clang-tidy/misc/ConfusableIdentifierCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc/confusable-identifiers.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/misc/confusable-identifiers.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/misc/confusable-identifiers.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/misc/confusable-identifiers.cpp
@@ -18,8 +18,26 @@
 int fi;
 // CHECK-MESSAGES: :[[#@LINE-1]]:5: note: other declaration found here
 
+bool f0(const char *q1, const char *ql) {
+  // CHECK-MESSAGES: :[[#@LINE-1]]:21: warning: q1 is confusable with ql 
[misc-confusable-identifiers]
+  // CHECK-MESSAGES: :[[#@LINE-2]]:37: note: other declaration found here
+  return q1 < ql;
+}
+
 // should not print anything
 namespace ns {
 struct Foo {};
 } // namespace ns
 auto f = ns::Foo();
+
+struct Test {
+  void f1(const char *pl);
+};
+
+bool f2(const char *p1, const char *ql) {
+  return p1 < ql;
+}
+
+bool f3(const char *q0, const char *q1) {
+  return q0 < q1;
+}
Index: clang-tools-extra/clang-tidy/misc/ConfusableIdentifierCheck.cpp
===
--- clang-tools-extra/clang-tidy/misc/ConfusableIdentifierCheck.cpp
+++ clang-tools-extra/clang-tidy/misc/ConfusableIdentifierCheck.cpp
@@ -99,10 +99,9 @@
 if (IdentifierInfo *II = ND->getIdentifier()) {
   StringRef NDName = II->getName();
   llvm::SmallVector &Mapped = Mapper[skeleton(NDName)];
-  const DeclContext *NDDecl = ND->getDeclContext();
   for (const NamedDecl *OND : Mapped) {
-if (!NDDecl->isDeclInLexicalTraversal(OND) &&
-!OND->getDeclContext()->isDeclInLexicalTraversal(ND))
+if (!ND->getDeclContext()->Encloses(OND->getDeclContext()) &&
+!OND->getDeclContext()->Encloses(ND->getDeclContext()))
   continue;
 if (OND->getIdentifier()->getName() != NDName) {
   diag(OND->getLocation(), "%0 is confusable with %1")


Index: clang-tools-extra/test/clang-tidy/checkers/misc/confusable-identifiers.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/misc/confusable-identifiers.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/misc/confusable-identifiers.cpp
@@ -18,8 +18,26 @@
 int fi;
 // CHECK-MESSAGES: :[[#@LINE-1]]:5: note: other declaration found here
 
+bool f0(const char *q1, const char *ql) {
+  // CHECK-MESSAGES: :[[#@LINE-1]]:21: warning: q1 is confusable with ql [misc-confusable-identifiers]
+  // CHECK-MESSAGES: :[[#@LINE-2]]:37: note: other declaration found here
+  return q1 < ql;
+}
+
 // should not print anything
 namespace ns {
 struct Foo {};
 } // namespace ns
 auto f = ns::Foo();
+
+struct Test {
+  void f1(const char *pl);
+};
+
+bool f2(const char *p1, const char *ql) {
+  return p1 < ql;
+}
+
+bool f3(const char *q0, const char *q1) {
+  return q0 < q1;
+}
Index: clang-tools-extra/clang-tidy/misc/ConfusableIdentifierCheck.cpp
===
--- clang-tools-extra/clang-tidy/misc/ConfusableIdentifierCheck.cpp
+++ clang-tools-extra/clang-tidy/misc/ConfusableIdentifierCheck.cpp
@@ -99,10 +99,9 @@
 if (IdentifierInfo *II = ND->getIdentifier()) {
   StringRef NDName = II->getName();
   llvm::SmallVector &Mapped = Mapper[skeleton(NDName)];
-  const DeclContext *NDDecl = ND->getDeclContext();
   for (const NamedDecl *OND : Mapped) {
-if (!NDDecl->isDeclInLexicalTraversal(OND) &&
-!OND->getDeclContext()->isDeclInLexicalTraversal(ND))
+if (!ND->getDeclContext()->Encloses(OND->getDeclContext()) &&
+!OND->getDeclContext()->Encloses(ND->getDeclContext()))
   continue;
 if (OND->getIdentifier()->getName() != NDName) {
   diag(OND->getLocation(), "%0 is confusable with %1")
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 5548e80 - [IR] Remove support for extractvalue constant expression

2022-06-28 Thread Nikita Popov via cfe-commits

Author: Nikita Popov
Date: 2022-06-28T10:40:17+02:00
New Revision: 5548e807b5777fdda167b6795e0e05432a6163f1

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

LOG: [IR] Remove support for extractvalue constant expression

This removes the extractvalue constant expression, as part of
https://discourse.llvm.org/t/rfc-remove-most-constant-expressions/63179.
extractvalue is already not supported in bitcode, so we do not need
to worry about bitcode auto-upgrade.

Uses of ConstantExpr::getExtractValue() should be replaced with
IRBuilder::CreateExtractValue() (if the fact that the result is
constant is not important) or ConstantFoldExtractValueInstruction()
(if it is). Though for this particular case, it is also possible
and usually preferable to use getAggregateElement() instead.

The C API function LLVMConstExtractValue() is removed, as the
underlying constant expression no longer exists. Instead,
LLVMBuildExtractValue() should be used (which will constant fold
or create an instruction). Depending on the use-case,
LLVMGetAggregateElement() may also be used instead.

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

Added: 
llvm/test/Assembler/unsupported-constexprs.ll

Modified: 
clang/lib/CodeGen/ItaniumCXXABI.cpp
llvm/bindings/go/llvm/ir.go
llvm/bindings/ocaml/llvm/llvm.ml
llvm/bindings/ocaml/llvm/llvm.mli
llvm/bindings/ocaml/llvm/llvm_ocaml.c
llvm/docs/ReleaseNotes.rst
llvm/include/llvm-c/Core.h
llvm/include/llvm/Analysis/TargetFolder.h
llvm/include/llvm/IR/ConstantFolder.h
llvm/include/llvm/IR/Constants.h
llvm/lib/Analysis/ConstantFolding.cpp
llvm/lib/Analysis/InlineCost.cpp
llvm/lib/AsmParser/LLParser.cpp
llvm/lib/IR/Constants.cpp
llvm/lib/IR/ConstantsContext.h
llvm/lib/IR/Core.cpp
llvm/lib/Transforms/Coroutines/CoroElide.cpp
llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
llvm/lib/Transforms/Utils/Evaluator.cpp
llvm/test/Assembler/insertextractvalue.ll
llvm/test/CodeGen/Generic/pr33094.ll
llvm/test/Transforms/InstCombine/cast.ll
llvm/test/Transforms/InstCombine/pr28725.ll
llvm/test/Transforms/InstSimplify/pr28725.ll

Removed: 
llvm/test/CodeGen/X86/nonconst-static-ev.ll



diff  --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp 
b/clang/lib/CodeGen/ItaniumCXXABI.cpp
index f51e9b303236b..c41b4192051a3 100644
--- a/clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -955,7 +955,7 @@ ItaniumCXXABI::EmitMemberPointerConversion(const CastExpr 
*E,
 adj = llvm::ConstantInt::get(adj->getType(), offset);
   }
 
-  llvm::Constant *srcAdj = llvm::ConstantExpr::getExtractValue(src, 1);
+  llvm::Constant *srcAdj = src->getAggregateElement(1);
   llvm::Constant *dstAdj;
   if (isDerivedToBase)
 dstAdj = llvm::ConstantExpr::getNSWSub(srcAdj, adj);

diff  --git a/llvm/bindings/go/llvm/ir.go b/llvm/bindings/go/llvm/ir.go
index 7bf92e60a2753..14cad0cb7ed30 100644
--- a/llvm/bindings/go/llvm/ir.go
+++ b/llvm/bindings/go/llvm/ir.go
@@ -993,20 +993,6 @@ func ConstShuffleVector(veca, vecb, mask Value) (rv Value) 
{
return
 }
 
-//TODO
-//LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned 
*IdxList,
-//   unsigned NumIdx);
-
-func ConstExtractValue(agg Value, indices []uint32) (rv Value) {
-   n := len(indices)
-   if n == 0 {
-   panic("one or more indices are required")
-   }
-   ptr := (*C.unsigned)(&indices[0])
-   rv.C = C.LLVMConstExtractValue(agg.C, ptr, C.unsigned(n))
-   return
-}
-
 func ConstInsertValue(agg, val Value, indices []uint32) (rv Value) {
n := len(indices)
if n == 0 {

diff  --git a/llvm/bindings/ocaml/llvm/llvm.ml 
b/llvm/bindings/ocaml/llvm/llvm.ml
index b20c113ef32e4..bf8b96959f819 100644
--- a/llvm/bindings/ocaml/llvm/llvm.ml
+++ b/llvm/bindings/ocaml/llvm/llvm.ml
@@ -704,8 +704,6 @@ external const_insertelement : llvalue -> llvalue -> 
llvalue -> llvalue
  = "LLVMConstInsertElement"
 external const_shufflevector : llvalue -> llvalue -> llvalue -> llvalue
  = "LLVMConstShuffleVector"
-external const_extractvalue : llvalue -> int array -> llvalue
-= "llvm_const_extractvalue"
 external const_insertvalue : llvalue -> llvalue -> int array -> llvalue
= "llvm_const_insertvalue"
 external const_inline_asm : lltype -> string -> string -> bool -> bool ->

diff  --git a/llvm/bindings/ocaml/llvm/llvm.mli 
b/llvm/bindings/ocaml/llvm/llvm.mli
index af303774e0b96..385c3cc272d15 100644
--- a/llvm/bindings/ocaml/llvm/llvm.mli
+++ b/llvm/bindings/ocaml/llvm/llvm.mli
@@ -1347,11 +1347,6 @@ val const_insertelement : llvalue -> llvalue -> 

[PATCH] D125795: [IR] Remove support for extractvalue constant expression

2022-06-28 Thread Nikita Popov via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5548e807b577: [IR] Remove support for extractvalue constant 
expression (authored by nikic).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D125795?vs=439367&id=440531#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125795

Files:
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  llvm/bindings/go/llvm/ir.go
  llvm/bindings/ocaml/llvm/llvm.ml
  llvm/bindings/ocaml/llvm/llvm.mli
  llvm/bindings/ocaml/llvm/llvm_ocaml.c
  llvm/docs/ReleaseNotes.rst
  llvm/include/llvm-c/Core.h
  llvm/include/llvm/Analysis/TargetFolder.h
  llvm/include/llvm/IR/ConstantFolder.h
  llvm/include/llvm/IR/Constants.h
  llvm/lib/Analysis/ConstantFolding.cpp
  llvm/lib/Analysis/InlineCost.cpp
  llvm/lib/AsmParser/LLParser.cpp
  llvm/lib/IR/Constants.cpp
  llvm/lib/IR/ConstantsContext.h
  llvm/lib/IR/Core.cpp
  llvm/lib/Transforms/Coroutines/CoroElide.cpp
  llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
  llvm/lib/Transforms/Utils/Evaluator.cpp
  llvm/test/Assembler/insertextractvalue.ll
  llvm/test/Assembler/unsupported-constexprs.ll
  llvm/test/CodeGen/Generic/pr33094.ll
  llvm/test/CodeGen/X86/nonconst-static-ev.ll
  llvm/test/Transforms/InstCombine/cast.ll
  llvm/test/Transforms/InstCombine/pr28725.ll
  llvm/test/Transforms/InstSimplify/pr28725.ll

Index: llvm/test/Transforms/InstSimplify/pr28725.ll
===
--- llvm/test/Transforms/InstSimplify/pr28725.ll
+++ llvm/test/Transforms/InstSimplify/pr28725.ll
@@ -1,12 +1,17 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
 ; RUN: opt -S -passes=instsimplify < %s | FileCheck %s
 %S = type { i16, i32 }
 
+; InstCombine will be able to fold this into zeroinitializer
 define <2 x i16> @test1() {
+; CHECK-LABEL: @test1(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:[[E:%.*]] = extractvalue [[S:%.*]] select (i1 icmp eq (i16 extractelement (<2 x i16> bitcast (<1 x i32>  to <2 x i16>), i32 0), i16 0), [[S]] zeroinitializer, [[S]] { i16 0, i32 1 }), 0
+; CHECK-NEXT:[[B:%.*]] = insertelement <2 x i16> , i16 [[E]], i32 0
+; CHECK-NEXT:ret <2 x i16> [[B]]
+;
 entry:
-  %b = insertelement <2 x i16> , i16 extractvalue (%S select (i1 icmp eq (i16 extractelement (<2 x i16> bitcast (<1 x i32>  to <2 x i16>), i32 0), i16 0), %S zeroinitializer, %S { i16 0, i32 1 }), 0), i32 0
+  %e = extractvalue %S select (i1 icmp eq (i16 extractelement (<2 x i16> bitcast (<1 x i32>  to <2 x i16>), i32 0), i16 0), %S zeroinitializer, %S { i16 0, i32 1 }), 0
+  %b = insertelement <2 x i16> , i16 %e, i32 0
   ret <2 x i16> %b
 }
-
-; InstCombine will be able to fold this into zeroinitializer
-; CHECK-LABEL: @test1(
-; CHECK: ret <2 x i16>  bitcast (<1 x i32>  to <2 x i16>), i32 0), i16 0), %S zeroinitializer, %S { i16 0, i32 1 }), 0), i16 0>
Index: llvm/test/Transforms/InstCombine/pr28725.ll
===
--- llvm/test/Transforms/InstCombine/pr28725.ll
+++ llvm/test/Transforms/InstCombine/pr28725.ll
@@ -3,7 +3,8 @@
 
 define <2 x i16> @test1() {
 entry:
-  %b = insertelement <2 x i16> , i16 extractvalue (%S select (i1 icmp eq (i16 extractelement (<2 x i16> bitcast (<1 x i32>  to <2 x i16>), i32 0), i16 0), %S zeroinitializer, %S { i16 0, i32 1 }), 0), i32 0
+  %e = extractvalue %S select (i1 icmp eq (i16 extractelement (<2 x i16> bitcast (<1 x i32>  to <2 x i16>), i32 0), i16 0), %S zeroinitializer, %S { i16 0, i32 1 }), 0
+  %b = insertelement <2 x i16> , i16 %e, i32 0
   ret <2 x i16> %b
 }
 
Index: llvm/test/Transforms/InstCombine/cast.ll
===
--- llvm/test/Transforms/InstCombine/cast.ll
+++ llvm/test/Transforms/InstCombine/cast.ll
@@ -1470,7 +1470,8 @@
 ; LE-LABEL: @PR28745(
 ; LE-NEXT:ret i64 0
 ;
-  %b = zext i32 extractvalue ({ i32 } select (i1 icmp eq (i16 extractelement (<2 x i16> bitcast (<1 x i32>  to <2 x i16>), i32 0), i16 0), { i32 } { i32 1 }, { i32 } zeroinitializer), 0) to i64
+  %e = extractvalue { i32 } select (i1 icmp eq (i16 extractelement (<2 x i16> bitcast (<1 x i32>  to <2 x i16>), i32 0), i16 0), { i32 } { i32 1 }, { i32 } zeroinitializer), 0
+  %b = zext i32 %e to i64
   ret i64 %b
 }
 
Index: llvm/test/CodeGen/X86/nonconst-static-ev.ll
===
--- llvm/test/CodeGen/X86/nonconst-static-ev.ll
+++ /dev/null
@@ -1,8 +0,0 @@
-; RUN: not --crash llc -mtriple=i686-linux-gnu < %s 2> %t
-; RUN: FileCheck --check-prefix=CHECK-ERRORS < %t %s
-
-@0 = global i8 extractvalue ([1 x i8] select (i1 ptrtoint (ptr @1 to i1), [1 x i8] [ i8 1 ], [1 x i8] [ i8 2 ]), 0)
-@1 = external global i32
-
-; CHECK-ERRORS: Unsupported expression in stat

[PATCH] D127873: [clang-format] Fix misplacement of `*` in declaration of pointer to struct

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

In D127873#3614559 , @jackhong12 
wrote:

> Sorry, I don't have commit access. @HazardyKnusperkeks, could you help me 
> commit it?
>
> If I want to contribute to LLVM in the future, how do I get the commit 
> permission? Does it depend on the number of patches I submit?

https://llvm.org/docs/DeveloperPolicy.html#obtaining-commit-access

I can push it for you, but if you want to get the commit access, you can wait 
and do it yourself. Just ask for it, I didn't have to wait long.


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

https://reviews.llvm.org/D127873

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


[PATCH] D128649: [clang-cl] Handle some pragma alloc_text corner cases handled by MSVC

2022-06-28 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

In D128649#3612875 , @steplong wrote:

>> Isn't the question whether `f` is considered "extern C" in the end or not? I 
>> thought `isExternC()` checks that? Are you saying it would return false for 
>> `f` in your example?
>
> Yup, `isExternC()` is returning false for that case because there's "static".

I see. It seems there's already some code that gives special treatment to 
"static extern c" functions in CodeGenModule::MaybeHandleStaticInExternC(): 
https://github.com/llvm/llvm-project/blob/llvmorg-14.0.6/clang/lib/CodeGen/CodeGenModule.cpp#L4420

Okay, I think this is almost ready. I just had one more comment about the 
if-statements above.




Comment at: clang/lib/Sema/SemaAttr.cpp:825
+  }
+} else if (!isa(ND)) {
+  Diag(Loc, diag::err_pragma_alloc_text_not_function);

Instead of checking this in two places, how about doing something like:

```
FunctionDecl *FD = dyn_cast(ND->getCanonicalDecl());
if (!FD) {
  // error
}
```

above right after the `if (!ND)` check? Then the C++ specific code just becomes

```
if (!FD->isInExternCContext()) {
  // error
}
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128649

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


[PATCH] D128709: [clang-format] Handle Verilog attributes

2022-06-28 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks accepted this revision.
HazardyKnusperkeks added a comment.
This revision is now accepted and ready to land.

Seems straight forward.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128709

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


[PATCH] D128712: [clang-format] Handle Verilog modules

2022-06-28 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added inline comments.



Comment at: clang/lib/Format/FormatToken.h:1742
+  /// Returns whether \p Tok is a Verilog keyword that opens a module, etc.
+  bool isVerilogHier(const FormatToken &Tok) const {
+if (Tok.endsSequence(kw_function, kw_with))

Please write it out.

For a german //hier// has a different meaning. ;)



Comment at: clang/lib/Format/TokenAnnotator.cpp:241
 bool StartsObjCMethodExpr = false;
-if (FormatToken *MaybeSel = OpeningParen.Previous) {
-  // @selector( starts a selector.
-  if (MaybeSel->isObjCAtKeyword(tok::objc_selector) && MaybeSel->Previous 
&&
-  MaybeSel->Previous->is(tok::at)) {
-StartsObjCMethodExpr = true;
+if (Style.isCpp()) {
+  if (FormatToken *MaybeSel = OpeningParen.Previous) {

?

I don't know where this is also used.

Let's see what the others say.



Comment at: clang/lib/Format/TokenAnnotator.cpp:766
   CurrentToken->setType(TT_AttributeColon);
-} else if (Left->isOneOf(TT_ArraySubscriptLSquare,
+} else if (Style.isCpp() &&
+   Left->isOneOf(TT_ArraySubscriptLSquare,

See above.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128712

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


[PATCH] D128645: Update developer policy.

2022-06-28 Thread Edd Barrett via Phabricator via cfe-commits
vext01 added inline comments.



Comment at: llvm/docs/DeveloperPolicy.rst:419-421
-Your first commit to a repository may require the autogenerated email to be
-approved by a moderator of the mailing list.
-This is normal and will be done when the mailing list owner has time.

aaron.ballman wrote:
> vext01 wrote:
> > aaron.ballman wrote:
> > > Rather than get rid of this, I think we might actually want to broaden 
> > > it. I read this blurb as letting folks know that sometimes commit 
> > > messages take a while before they show up on the commit list. It used to 
> > > be the primary way that happened was when making a commit for the first 
> > > time. Now it happens most often for large commits (due to the size of the 
> > > email content) or a long list of CCs (often added automatically by 
> > > Herald, though the moderation of these has gotten better in recent 
> > > history).
> > > 
> > > I think it's kind of helpful to let people know that sometimes the 
> > > automated emails get caught out by moderation. But if others don't think 
> > > that's of value to mention, then we can go ahead and remove this bit.
> > Actually, now I read it again, I realise that I don't understand what this 
> > sentence means:
> > 
> > > Your first commit to a repository may require the autogenerated email to 
> > > be approved by a moderator of the mailing list.
> > 
> > My first commit to a llvm repository was via github, and github doesn't 
> > discriminate. If you have write-access to the repo, then your push to 
> > `main` will surely go ahead. There are no automated emails involved as far 
> > as I know.
> > 
> > I suspect this prose is from pre-github, where the process was different?
> > Actually, now I read it again, I realise that I don't understand what this 
> > sentence means:
> 
> Ah, I think I see where the confusion may be coming in.
> 
> We have a post-commit hook that pushes all commits to a commits email list: 
> https://lists.llvm.org/pipermail/cfe-commits/ (as an example, there's also 
> commits list for LLVM and others), and it's existed for a *long time*. It 
> used to be that your commits were written to the commits list as though they 
> came from you directly (e.g., 
> https://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20130225/074838.html),
>  and these days they come in as though from a list bot (e.g., 
> https://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20220627/424937.html);
>  check out the from line just below the title to spot the differences. So the 
> old issue was that when you first pushed a commit, you may not have been 
> subscribed to cfe-commits and your commit message wouldn't make it to the 
> lists. Now the issue is that when you push any commit, it might be caught up 
> by moderation filters (this also used to be an issue, but it wasn't the most 
> likely issue for people to hit).
OK, so what do you recommend we do? This prose is currently full of historic 
details that are confusing/intimidating for a newbie.

Does the sentence still apply, or can we kill it? 


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

https://reviews.llvm.org/D128645

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


[PATCH] D128714: [clang-format] Handle Verilog case statements

2022-06-28 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added inline comments.



Comment at: clang/lib/Format/Format.cpp:1265
   LLVMStyle.IndentAccessModifiers = false;
-  LLVMStyle.IndentCaseLabels = false;
+  LLVMStyle.IndentCaseLabels = LLVMStyle.isVerilog() ? true : false;
   LLVMStyle.IndentCaseBlocks = false;

You should put that below.



Comment at: clang/lib/Format/Format.cpp:1349
 
   // Defaults that differ when not C++.
   if (Language == FormatStyle::LK_TableGen)

Here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128714

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


[PATCH] D127812: [AArch64] Function multiversioning support added.

2022-06-28 Thread Sam Tebbs via Phabricator via cfe-commits
samtebbs added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:11483
+def warn_target_clone_no_impact_options
+: Warning<"version list contains no code impact entries">,
+  InGroup;

ilinpv wrote:
> erichkeane wrote:
> > I'm not clear as to what this means?
> It gives a warning if target_clones attributes contains features which have 
> no impact on code generation ( no supported yet ) and ignored. They has 
> "" OPTION in llvm/include/llvm/Support/AArch64TargetParser.def 
> See clang/test/Sema/attr-target-clones-aarch64.c tests
> ```
> // expected-warning@+1 {{version list contains no code impact entries}}
> void __attribute__((target_clones("sha1+pmull"))) warn2(void);
> 
> // expected-warning@+1 {{version list contains no code impact entries}}
> int __attribute__((target_clones("rng", "fhm+dpb+sha1", "default"))) 
> redecl4(void) { return 1; }
> ```
Perhaps it would be better to warn with something like "version list contains 
entries that don't impact code generation". I think that would be more clear.



Comment at: clang/include/clang/Basic/TargetInfo.h:1311
+  /// generation.
+  virtual bool isCodeImpactFeatureName(StringRef Feature) const { return true; 
}
+

Similarly to the warning string, I think a name like 
`featureAffectsCodeGen(...)` would be more clear in its use.



Comment at: clang/lib/Basic/Targets/AArch64.cpp:663
+if (Feature == "-fmv") {
+  HasFMV = false;
+}

Slight nit, but braces aren't needed here.



Comment at: clang/lib/CodeGen/CodeGenFunction.cpp:2561
   } else if (!TargetDecl->isMultiVersion() &&
- TargetDecl->hasAttr()) {
+ (TargetDecl->hasAttr())) {
 // Get the required features for the callee.

Parentheses not needed.



Comment at: clang/lib/CodeGen/CodeGenFunction.cpp:2664
+  default:
+assert(false && "Only implemented for x86 and AArch64 targets");
+  }

I'm not 100% sure on the differences between `assert(..)` and 
`LLvm_unreachable(...)`, but perhaps that would be cleaner than an assertion on 
`false`.



Comment at: clang/lib/CodeGen/CodeGenFunction.cpp:2670
+llvm::Function *Resolver, ArrayRef Options) {
+  assert(!Options.empty() && "No Multiversion Resolver Options Found");
+  assert(Options.back().Conditions.Features.size() == 0 &&

Nit on the capital letters for every word. Only "No" requires capitalisation.



Comment at: clang/lib/Sema/SemaDecl.cpp:10497
+  (TA || TVA) &&
+  "MultiVersion Candidate requires a target or target_version attribute");
   const TargetInfo &TargetInfo = S.Context.getTargetInfo();

Candidate doesn't need capitalisation either.



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:3521
 bool DefaultIsDupe = false;
+bool IsCodeImpact = false;
 if (Cur.empty())

I think `HasCodeImpact` would be more explanatory.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127812

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


[PATCH] D128704: [clang-extdef-mapping] Directly process .ast files

2022-06-28 Thread Tobias Hieta via Phabricator via cfe-commits
thieta updated this revision to Diff 440558.
thieta added a comment.

Add test. Just repurpose the same test we already have but add a step to
generate ast first and then pushing that through extdef-mapping. It should
always produce the same result.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128704

Files:
  clang/test/Analysis/func-mapping-test.cpp
  clang/tools/clang-extdef-mapping/ClangExtDefMapGen.cpp

Index: clang/tools/clang-extdef-mapping/ClangExtDefMapGen.cpp
===
--- clang/tools/clang-extdef-mapping/ClangExtDefMapGen.cpp
+++ clang/tools/clang-extdef-mapping/ClangExtDefMapGen.cpp
@@ -1,4 +1,4 @@
-//===- ClangExtDefMapGen.cpp ---===//
+//===- ClangExtDefMapGen.cpp -===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -13,10 +13,12 @@
 
 #include "clang/AST/ASTConsumer.h"
 #include "clang/AST/ASTContext.h"
+#include "clang/Basic/DiagnosticOptions.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/CrossTU/CrossTranslationUnit.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/FrontendActions.h"
+#include "clang/Frontend/TextDiagnosticPrinter.h"
 #include "clang/Tooling/CommonOptionsParser.h"
 #include "clang/Tooling/Tooling.h"
 #include "llvm/Support/CommandLine.h"
@@ -29,12 +31,16 @@
 using namespace clang::cross_tu;
 using namespace clang::tooling;
 
-static cl::OptionCategory ClangExtDefMapGenCategory("clang-extdefmapgen options");
+static cl::OptionCategory
+ClangExtDefMapGenCategory("clang-extdefmapgen options");
 
 class MapExtDefNamesConsumer : public ASTConsumer {
 public:
-  MapExtDefNamesConsumer(ASTContext &Context)
-  : Ctx(Context), SM(Context.getSourceManager()) {}
+  MapExtDefNamesConsumer(ASTContext &Context,
+ StringRef astFilePath = StringRef())
+  : Ctx(Context), SM(Context.getSourceManager()) {
+CurrentFileName = astFilePath.str();
+  }
 
   ~MapExtDefNamesConsumer() {
 // Flush results to standard output.
@@ -111,6 +117,46 @@
 
 static cl::extrahelp CommonHelp(CommonOptionsParser::HelpMessage);
 
+void HandleAST(StringRef astPath) {
+
+  CompilerInstance CI;
+
+  IntrusiveRefCntPtr DiagOpts = new DiagnosticOptions();
+  TextDiagnosticPrinter *DiagClient =
+  new TextDiagnosticPrinter(llvm::errs(), &*DiagOpts);
+  IntrusiveRefCntPtr DiagID(new DiagnosticIDs());
+  IntrusiveRefCntPtr Diags(
+  new DiagnosticsEngine(DiagID, &*DiagOpts, DiagClient));
+
+  std::unique_ptr unit = ASTUnit::LoadFromASTFile(
+  astPath.str(), CI.getPCHContainerOperations()->getRawReader(),
+  ASTUnit::LoadASTOnly, Diags, CI.getFileSystemOpts());
+
+  FileManager fm(CI.getFileSystemOpts());
+  SmallString<128> absPath(astPath);
+  fm.makeAbsolutePath(absPath);
+
+  std::unique_ptr consumer =
+  std::make_unique(unit->getASTContext(), absPath);
+  consumer->HandleTranslationUnit(unit->getASTContext());
+}
+
+void HandleFiles(ArrayRef sourceFiles,
+ CompilationDatabase &compilations) {
+  std::vector sourceToBeParsed;
+  for (StringRef src : sourceFiles) {
+if (src.endswith(".ast"))
+  HandleAST(src);
+else
+  sourceToBeParsed.push_back(src.str());
+  }
+
+  if (!sourceToBeParsed.empty()) {
+ClangTool Tool(compilations, sourceToBeParsed);
+Tool.run(newFrontendActionFactory().get());
+  }
+}
+
 int main(int argc, const char **argv) {
   // Print a stack trace if we signal out.
   sys::PrintStackTraceOnErrorSignal(argv[0], false);
@@ -127,8 +173,6 @@
   }
   CommonOptionsParser &OptionsParser = ExpectedParser.get();
 
-  ClangTool Tool(OptionsParser.getCompilations(),
- OptionsParser.getSourcePathList());
-
-  return Tool.run(newFrontendActionFactory().get());
+  HandleFiles(OptionsParser.getSourcePathList(),
+  OptionsParser.getCompilations());
 }
Index: clang/test/Analysis/func-mapping-test.cpp
===
--- clang/test/Analysis/func-mapping-test.cpp
+++ clang/test/Analysis/func-mapping-test.cpp
@@ -1,4 +1,6 @@
 // RUN: %clang_extdef_map %s -- | FileCheck --implicit-check-not "c:@y" --implicit-check-not "c:@z" %s
+// RUN: %clang -emit-ast %s -o %t.ast
+// RUN: %clang_extdef_map %t.ast -- | FileCheck --implicit-check-not "c:@y" --implicit-check-not "c:@z" %s
 
 int f(int) {
   return 0;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D128704: [clang-extdef-mapping] Directly process .ast files

2022-06-28 Thread Tobias Hieta via Phabricator via cfe-commits
thieta added inline comments.



Comment at: clang/tools/clang-extdef-mapping/ClangExtDefMapGen.cpp:122
+
+  CompilerInstance CI;
+

Not sure if I can just create a compilerinstance here and if I should feed it 
anymore data then I already do.



Comment at: clang/tools/clang-extdef-mapping/ClangExtDefMapGen.cpp:135
+
+  FileManager fm(CI.getFileSystemOpts());
+  SmallString<128> absPath(astPath);

For some reason CI.getFileManager() often returns no filemanager - but 
sometimes it works? I just ended up creating my own to make the path absolute.



Comment at: clang/tools/clang-extdef-mapping/ClangExtDefMapGen.cpp:136
+  FileManager fm(CI.getFileSystemOpts());
+  SmallString<128> absPath(astPath);
+  fm.makeAbsolutePath(absPath);

Pretty sure 128 is wrong here - but I searched the codebase and that seems to 
be the most common size used? I couldn't find anything using PATH_MAX or 
something like that.



Comment at: clang/tools/clang-extdef-mapping/ClangExtDefMapGen.cpp:141
+  std::make_unique(unit->getASTContext(), absPath);
+  consumer->HandleTranslationUnit(unit->getASTContext());
+}

I tried to figure out how to "run" the consumer on a already loaded ASTUnit - 
but I didn't find anything in the api for that and this way works since it's 
more or less what will happen when the consumer is executed anyway.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128704

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


[PATCH] D117432: [RISCV] Implement support for the Zicbom and Zicboz extensions

2022-06-28 Thread Alex Bradbury 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 rG4f40ca53cefb: [RISCV] Implement support for the Zicbom and 
Zicboz extensions (authored by asb).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D117432?vs=415498&id=440563#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117432

Files:
  clang/test/Preprocessor/riscv-target-features.c
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/RISCV.td
  llvm/lib/Target/RISCV/RISCVInstrInfo.td
  llvm/lib/Target/RISCV/RISCVInstrInfoZicbo.td
  llvm/lib/Target/RISCV/RISCVSubtarget.h
  llvm/test/CodeGen/RISCV/attributes.ll
  llvm/test/MC/RISCV/attribute-arch.s
  llvm/test/MC/RISCV/rv32zicbom-invalid.s
  llvm/test/MC/RISCV/rv32zicbom-valid.s
  llvm/test/MC/RISCV/rv32zicboz-invalid.s
  llvm/test/MC/RISCV/rv32zicboz-valid.s

Index: llvm/test/MC/RISCV/rv32zicboz-valid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rv32zicboz-valid.s
@@ -0,0 +1,17 @@
+# RUN: llvm-mc %s -triple=riscv32 -mattr=+zicboz -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc %s -triple=riscv64 -mattr=+zicboz -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc -filetype=obj -triple=riscv32 -mattr=+zicboz < %s \
+# RUN: | llvm-objdump --mattr=+zicboz -d -r - \
+# RUN: | FileCheck --check-prefix=CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+zicboz < %s \
+# RUN: | llvm-objdump --mattr=+zicboz -d -r - \
+# RUN: | FileCheck --check-prefix=CHECK-ASM-AND-OBJ %s
+
+# CHECK-ASM-AND-OBJ: cbo.zero (t0)
+# CHECK-ASM: encoding: [0x0f,0xa0,0x42,0x00]
+cbo.zero (t0)
+# CHECK-ASM-AND-OBJ: cbo.zero (t0)
+# CHECK-ASM: encoding: [0x0f,0xa0,0x42,0x00]
+cbo.zero 0(t0)
Index: llvm/test/MC/RISCV/rv32zicboz-invalid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rv32zicboz-invalid.s
@@ -0,0 +1,16 @@
+# RUN: not llvm-mc -triple riscv32 -mattr=+zicboz < %s 2>&1 | FileCheck %s
+# RUN: not llvm-mc -triple riscv64 -mattr=+zicboz < %s 2>&1 | FileCheck %s
+
+# Must have a single register argument.
+cbo.zero # CHECK: :[[@LINE]]:1: error: too few operands for instruction
+cbo.zero 1 # CHECK: :[[@LINE]]:12: error: expected '(' after optional integer offset
+cbo.zero t0, t1 # CHECK: :[[@LINE]]:10: error: expected '(' or optional integer offset
+
+# Non-zero offsets are not supported.
+cbo.zero 1(t0) # CHECK: :[[@LINE]]:10: error: optional integer offset must be 0
+
+# Instructions from other zicbo* extensions aren't available without enabling
+# the appropriate -mattr flag.
+cbo.clean (t0) # CHECK: :[[@LINE]]:1: error: instruction requires the following: 'Zicbom' (Cache-Block Management Instructions)
+cbo.flush (t1) # CHECK: :[[@LINE]]:1: error: instruction requires the following: 'Zicbom' (Cache-Block Management Instructions)
+cbo.inval (t2) # CHECK: :[[@LINE]]:1: error: instruction requires the following: 'Zicbom' (Cache-Block Management Instructions)
Index: llvm/test/MC/RISCV/rv32zicbom-valid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rv32zicbom-valid.s
@@ -0,0 +1,31 @@
+# RUN: llvm-mc %s -triple=riscv32 -mattr=+zicbom -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc %s -triple=riscv64 -mattr=+zicbom -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc -filetype=obj -triple=riscv32 -mattr=+zicbom < %s \
+# RUN: | llvm-objdump --mattr=+zicbom -d -r - \
+# RUN: | FileCheck --check-prefix=CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+zicbom < %s \
+# RUN: | llvm-objdump --mattr=+zicbom -d -r - \
+# RUN: | FileCheck --check-prefix=CHECK-ASM-AND-OBJ %s
+
+# CHECK-ASM-AND-OBJ: cbo.clean (t0)
+# CHECK-ASM: encoding: [0x0f,0xa0,0x12,0x00]
+cbo.clean (t0)
+# CHECK-ASM-AND-OBJ: cbo.clean (t0)
+# CHECK-ASM: encoding: [0x0f,0xa0,0x12,0x00]
+cbo.clean 0(t0)
+
+# CHECK-ASM-AND-OBJ: cbo.flush (t1)
+# CHECK-ASM: encoding: [0x0f,0x20,0x23,0x00]
+cbo.flush (t1)
+# CHECK-ASM-AND-OBJ: cbo.flush (t1)
+# CHECK-ASM: encoding: [0x0f,0x20,0x23,0x00]
+cbo.flush 0(t1)
+
+# CHECK-ASM-AND-OBJ: cbo.inval (t2)
+# CHECK-ASM: encoding: [0x0f,0xa0,0x03,0x00]
+cbo.inval (t2)
+# CHECK-ASM-AND-OBJ: cbo.inval (t2)
+# CHECK-ASM: encoding: [0x0f,0xa0,0x03,0x00]
+cbo.inval 0(t2)
Index: llvm/test/MC/RISCV/rv32zicbom-invalid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rv32zicbom-invalid.s
@@ -0,0 +1,24 @@
+# RUN: not llvm-mc -triple riscv32 -mattr=+zicbom < %s 2>&1 | Fi

[PATCH] D117433: [RISCV] Implement support for the Zicbop extension

2022-06-28 Thread Alex Bradbury 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 rG7bcfcabbd14e: [RISCV] Implement support for the Zicbop 
extension (authored by asb).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D117433?vs=415500&id=440564#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117433

Files:
  clang/test/Preprocessor/riscv-target-features.c
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h
  llvm/lib/Target/RISCV/RISCV.td
  llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
  llvm/lib/Target/RISCV/RISCVInstrInfoZicbo.td
  llvm/lib/Target/RISCV/RISCVSubtarget.h
  llvm/test/CodeGen/RISCV/attributes.ll
  llvm/test/MC/RISCV/attribute-arch.s
  llvm/test/MC/RISCV/rv32zicbom-invalid.s
  llvm/test/MC/RISCV/rv32zicbop-invalid.s
  llvm/test/MC/RISCV/rv32zicbop-valid.s
  llvm/test/MC/RISCV/rv32zicboz-invalid.s

Index: llvm/test/MC/RISCV/rv32zicboz-invalid.s
===
--- llvm/test/MC/RISCV/rv32zicboz-invalid.s
+++ llvm/test/MC/RISCV/rv32zicboz-invalid.s
@@ -14,3 +14,6 @@
 cbo.clean (t0) # CHECK: :[[@LINE]]:1: error: instruction requires the following: 'Zicbom' (Cache-Block Management Instructions)
 cbo.flush (t1) # CHECK: :[[@LINE]]:1: error: instruction requires the following: 'Zicbom' (Cache-Block Management Instructions)
 cbo.inval (t2) # CHECK: :[[@LINE]]:1: error: instruction requires the following: 'Zicbom' (Cache-Block Management Instructions)
+prefetch.i 0(t3) # CHECK: :[[@LINE]]:1: error: instruction requires the following: 'Zicbop' (Cache-Block Prefetch Instructions)
+prefetch.r 0(t4) # CHECK: :[[@LINE]]:1: error: instruction requires the following: 'Zicbop' (Cache-Block Prefetch Instructions)
+prefetch.w 0(t5) # CHECK: :[[@LINE]]:1: error: instruction requires the following: 'Zicbop' (Cache-Block Prefetch Instructions)
Index: llvm/test/MC/RISCV/rv32zicbop-valid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rv32zicbop-valid.s
@@ -0,0 +1,40 @@
+# RUN: llvm-mc %s -triple=riscv32 -mattr=+zicbop -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc %s -triple=riscv64 -mattr=+zicbop -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc -filetype=obj -triple=riscv32 -mattr=+zicbop < %s \
+# RUN: | llvm-objdump --mattr=+zicbop -d -r - \
+# RUN: | FileCheck --check-prefix=CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+zicbop < %s \
+# RUN: | llvm-objdump --mattr=+zicbop -d -r - \
+# RUN: | FileCheck --check-prefix=CHECK-ASM-AND-OBJ %s
+
+# CHECK-ASM-AND-OBJ: prefetch.i -2048(t0)
+# CHECK-ASM: encoding: [0x13,0xe0,0x02,0x80]
+prefetch.i -2048(t0)
+# CHECK-ASM-AND-OBJ: prefetch.i 2016(t0)
+# CHECK-ASM: encoding: [0x13,0xe0,0x02,0x7e]
+prefetch.i 2016(t0)
+
+# CHECK-ASM-AND-OBJ: prefetch.r -2048(t1)
+# CHECK-ASM: encoding: [0x13,0x60,0x13,0x80]
+prefetch.r -0x800(t1)
+# CHECK-ASM-AND-OBJ: prefetch.r 2016(t1)
+# CHECK-ASM: encoding: [0x13,0x60,0x13,0x7e]
+prefetch.r 0x7e0(t1)
+
+# CHECK-ASM-AND-OBJ: prefetch.w -2048(t2)
+# CHECK-ASM: encoding: [0x13,0xe0,0x33,0x80]
+prefetch.w -2048(t2)
+# CHECK-ASM-AND-OBJ: prefetch.w 2016(t2)
+# CHECK-ASM: encoding: [0x13,0xe0,0x33,0x7e]
+prefetch.w 2016(t2)
+
+# Ensure that enabling zicbop doesn't cause issues decoding ori instructions.
+
+# CHECK-ASM-AND-OBJ: ori a0, a1, -2048
+# CHECK-ASM: encoding: [0x13,0xe5,0x05,0x80]
+ori a0, a1, -2048
+# CHECK-ASM-AND-OBJ: ori a0, a1, 0
+# CHECK-ASM: encoding: [0x13,0xe5,0x05,0x00]
+ori a0, a1, 0
Index: llvm/test/MC/RISCV/rv32zicbop-invalid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rv32zicbop-invalid.s
@@ -0,0 +1,29 @@
+# RUN: not llvm-mc -triple riscv32 -mattr=+zicbop < %s 2>&1 | FileCheck %s
+# RUN: not llvm-mc -triple riscv64 -mattr=+zicbop < %s 2>&1 | FileCheck %s
+
+# Memory operand not formatted correctly.
+prefetch.i a0, 32 # CHECK: :[[@LINE]]:12: error: immediate must be a multiple of 32 bytes in the range [-2048, 2016]
+prefetch.r 32, a0 # CHECK: :[[@LINE]]:16: error: invalid operand for instruction
+prefetch.w a0(32) # CHECK: :[[@LINE]]:14: error: unexpected token
+
+# Out of range offset.
+prefetch.i -2080(a0) # CHECK: :[[@LINE]]:12: error: immediate must be a multiple of 32 bytes in the range [-2048, 2016]
+prefetch.r 2048(a0) # CHECK: :[[@LINE]]:12: error: immediate must be a multiple of 32 bytes in the range [-2048, 2016]
+prefetch.w 2050(a0) # CHECK: :[[@LINE]]:12: error: immediate must be a multiple of 32 bytes in the range [-2048, 2016]
+
+# Offsets that aren't multiples of 32.
+pref

[clang] 4f40ca5 - [RISCV] Implement support for the Zicbom and Zicboz extensions

2022-06-28 Thread Alex Bradbury via cfe-commits

Author: Alex Bradbury
Date: 2022-06-28T12:43:25+01:00
New Revision: 4f40ca53cefb725aca6564585d0ec4836a79e21a

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

LOG: [RISCV] Implement support for the Zicbom and Zicboz extensions

Implements the ratified RISC-V Base Cache Management Operation ISA
Extensions: Zicbom and Zicboz, as described in
https://github.com/riscv/riscv-CMOs/blob/master/specifications/cmobase-v1.0.pdf.

Zicbop is implemented in a separate patch due to it requiring a new ASM
operand type to be defined.

As discussed in the relevant issue in the upstream spec
https://github.com/riscv/riscv-CMOs/issues/47, the cbo.* instructions
use the format (rs1) or 0(rs1) for their operand, similar to the AMOs.

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

Added: 
llvm/lib/Target/RISCV/RISCVInstrInfoZicbo.td
llvm/test/MC/RISCV/rv32zicbom-invalid.s
llvm/test/MC/RISCV/rv32zicbom-valid.s
llvm/test/MC/RISCV/rv32zicboz-invalid.s
llvm/test/MC/RISCV/rv32zicboz-valid.s

Modified: 
clang/test/Preprocessor/riscv-target-features.c
llvm/lib/Support/RISCVISAInfo.cpp
llvm/lib/Target/RISCV/RISCV.td
llvm/lib/Target/RISCV/RISCVInstrInfo.td
llvm/lib/Target/RISCV/RISCVSubtarget.h
llvm/test/CodeGen/RISCV/attributes.ll
llvm/test/MC/RISCV/attribute-arch.s

Removed: 




diff  --git a/clang/test/Preprocessor/riscv-target-features.c 
b/clang/test/Preprocessor/riscv-target-features.c
index edd66fb0cc4b9..02af5d8d6b21e 100644
--- a/clang/test/Preprocessor/riscv-target-features.c
+++ b/clang/test/Preprocessor/riscv-target-features.c
@@ -42,6 +42,8 @@
 // CHECK-NOT: __riscv_zkr
 // CHECK-NOT: __riscv_zkt
 // CHECK-NOT: __riscv_zk
+// CHECK-NOT: __riscv_zicbom
+// CHECK-NOT: __riscv_zicboz
 
 // RUN: %clang -target riscv32-unknown-linux-gnu -march=rv32im -x c -E -dM %s \
 // RUN: -o - | FileCheck --check-prefix=CHECK-M-EXT %s
@@ -433,3 +435,15 @@
 // RUN: -march=rv64i_zbkb_zbkc_zbkx_zksed_zksh -x c -E -dM %s -o - \
 // RUN: | FileCheck --check-prefix=CHECK-COMBINE-INTO-ZKS %s
 // CHECK-COMBINE-INTO-ZKS: __riscv_zks 1
+
+// RUN: %clang -target riscv32 -march=rv32izicbom -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-ZICBOM-EXT %s
+// RUN: %clang -target riscv64 -march=rv64izicbom -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-ZICBOM-EXT %s
+// CHECK-ZICBOM-EXT: __riscv_zicbom 100{{$}}
+
+// RUN: %clang -target riscv32 -march=rv32izicboz -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-ZICBOZ-EXT %s
+// RUN: %clang -target riscv64 -march=rv64izicboz -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-ZICBOZ-EXT %s
+// CHECK-ZICBOZ-EXT: __riscv_zicboz 100{{$}}

diff  --git a/llvm/lib/Support/RISCVISAInfo.cpp 
b/llvm/lib/Support/RISCVISAInfo.cpp
index 1057dbae13da9..9ff5fbe10bb4c 100644
--- a/llvm/lib/Support/RISCVISAInfo.cpp
+++ b/llvm/lib/Support/RISCVISAInfo.cpp
@@ -95,6 +95,9 @@ static const RISCVSupportedExtension SupportedExtensions[] = {
 {"zve64x", RISCVExtensionVersion{1, 0}},
 {"zve64f", RISCVExtensionVersion{1, 0}},
 {"zve64d", RISCVExtensionVersion{1, 0}},
+
+{"zicbom", RISCVExtensionVersion{1, 0}},
+{"zicboz", RISCVExtensionVersion{1, 0}},
 };
 
 static const RISCVSupportedExtension SupportedExperimentalExtensions[] = {

diff  --git a/llvm/lib/Target/RISCV/RISCV.td b/llvm/lib/Target/RISCV/RISCV.td
index 657f89ca18411..9b36598116a11 100644
--- a/llvm/lib/Target/RISCV/RISCV.td
+++ b/llvm/lib/Target/RISCV/RISCV.td
@@ -400,6 +400,20 @@ def FeatureStdExtZvfh
"'Zvfh' (Vector Half-Precision Floating-Point)",
[FeatureStdExtZve32f]>;
 
+def FeatureStdExtZicbom
+: SubtargetFeature<"zicbom", "HasStdExtZicbom", "true",
+   "'Zicbom' (Cache-Block Management Instructions)">;
+def HasStdExtZicbom : Predicate<"Subtarget->hasStdExtZicbom()">,
+AssemblerPredicate<(all_of 
FeatureStdExtZicbom),
+"'Zicbom' (Cache-Block Management 
Instructions)">;
+
+def FeatureStdExtZicboz
+: SubtargetFeature<"zicboz", "HasStdExtZicboz", "true",
+   "'Zicboz' (Cache-Block Zero Instructions)">;
+def HasStdExtZicboz : Predicate<"Subtarget->hasStdExtZicboz()">,
+AssemblerPredicate<(all_of 
FeatureStdExtZicboz),
+"'Zicboz' (Cache-Block Zero Instructions)">;
+
 def Feature64Bit
 : SubtargetFeature<"64bit", "HasRV64", "true", "Implements RV64">;
 def IsRV64 : Predicate<"Subtarget->is64Bit()">,

diff  --git a/llvm/lib/Target/RISCV/RISCVInstrInfo.td 
b/llvm/lib/Target/RISCV/RISCVInstrInfo.td
index 7e907a6f91a2d..ee4c026af8f43 100644
--- a/llvm/lib/Target/RISCV/RISCVInstrInfo.td

[clang] 7bcfcab - [RISCV] Implement support for the Zicbop extension

2022-06-28 Thread Alex Bradbury via cfe-commits

Author: Alex Bradbury
Date: 2022-06-28T12:43:26+01:00
New Revision: 7bcfcabbd14e9cd51d150a36aee9edf4f4231724

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

LOG: [RISCV] Implement support for the Zicbop extension

Implements the ratified RISC-V Base Cache Management Operation ISA
Extension: Zicbop, as described in
https://github.com/riscv/riscv-CMOs/blob/master/specifications/cmobase-v1.0.pdf.

This is implemented in a separate patch to Zicbom and Zicboz due to it
requiring a new ASM operand type to be defined.

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

Added: 
llvm/test/MC/RISCV/rv32zicbop-invalid.s
llvm/test/MC/RISCV/rv32zicbop-valid.s

Modified: 
clang/test/Preprocessor/riscv-target-features.c
llvm/lib/Support/RISCVISAInfo.cpp
llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h
llvm/lib/Target/RISCV/RISCV.td
llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
llvm/lib/Target/RISCV/RISCVInstrInfoZicbo.td
llvm/lib/Target/RISCV/RISCVSubtarget.h
llvm/test/CodeGen/RISCV/attributes.ll
llvm/test/MC/RISCV/attribute-arch.s
llvm/test/MC/RISCV/rv32zicbom-invalid.s
llvm/test/MC/RISCV/rv32zicboz-invalid.s

Removed: 




diff  --git a/clang/test/Preprocessor/riscv-target-features.c 
b/clang/test/Preprocessor/riscv-target-features.c
index 02af5d8d6b21e..38cef26cdc845 100644
--- a/clang/test/Preprocessor/riscv-target-features.c
+++ b/clang/test/Preprocessor/riscv-target-features.c
@@ -447,3 +447,9 @@
 // RUN: %clang -target riscv64 -march=rv64izicboz -x c -E -dM %s \
 // RUN: -o - | FileCheck --check-prefix=CHECK-ZICBOZ-EXT %s
 // CHECK-ZICBOZ-EXT: __riscv_zicboz 100{{$}}
+
+// RUN: %clang -target riscv32 -march=rv32izicbop -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-ZICBOP-EXT %s
+// RUN: %clang -target riscv64 -march=rv64izicbop -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-ZICBOP-EXT %s
+// CHECK-ZICBOP-EXT: __riscv_zicbop 100{{$}}

diff  --git a/llvm/lib/Support/RISCVISAInfo.cpp 
b/llvm/lib/Support/RISCVISAInfo.cpp
index 9ff5fbe10bb4c..7fe04af4696b8 100644
--- a/llvm/lib/Support/RISCVISAInfo.cpp
+++ b/llvm/lib/Support/RISCVISAInfo.cpp
@@ -98,6 +98,7 @@ static const RISCVSupportedExtension SupportedExtensions[] = {
 
 {"zicbom", RISCVExtensionVersion{1, 0}},
 {"zicboz", RISCVExtensionVersion{1, 0}},
+{"zicbop", RISCVExtensionVersion{1, 0}},
 };
 
 static const RISCVSupportedExtension SupportedExperimentalExtensions[] = {

diff  --git a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp 
b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
index 9c59c7bc57554..69fb9d2844d39 100644
--- a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
+++ b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
@@ -689,6 +689,16 @@ struct RISCVOperand : public MCParsedAsmOperand {
 
   bool isSImm12Lsb0() const { return isBareSimmNLsb0<12>(); }
 
+  bool isSImm12Lsb0() const {
+if (!isImm())
+  return false;
+RISCVMCExpr::VariantKind VK = RISCVMCExpr::VK_RISCV_None;
+int64_t Imm;
+bool IsConstantImm = evaluateConstantImm(getImm(), Imm, VK);
+return IsConstantImm && isShiftedInt<7, 5>(Imm) &&
+   VK == RISCVMCExpr::VK_RISCV_None;
+  }
+
   bool isSImm13Lsb0() const { return isBareSimmNLsb0<13>(); }
 
   bool isSImm10LsbNonZero() const {
@@ -1198,6 +1208,10 @@ bool RISCVAsmParser::MatchAndEmitInstruction(SMLoc 
IDLoc, unsigned &Opcode,
 return generateImmOutOfRangeError(
 Operands, ErrorInfo, -(1 << 11), (1 << 11) - 2,
 "immediate must be a multiple of 2 bytes in the range");
+  case Match_InvalidSImm12Lsb0:
+return generateImmOutOfRangeError(
+Operands, ErrorInfo, -(1 << 11), (1 << 11) - 32,
+"immediate must be a multiple of 32 bytes in the range");
   case Match_InvalidSImm13Lsb0:
 return generateImmOutOfRangeError(
 Operands, ErrorInfo, -(1 << 12), (1 << 12) - 2,

diff  --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h 
b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h
index b0b3dc4fe7df0..fa408f7fc5d7d 100644
--- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h
+++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h
@@ -221,6 +221,7 @@ enum OperandType : unsigned {
   OPERAND_UIMM7,
   OPERAND_UIMM12,
   OPERAND_SIMM12,
+  OPERAND_SIMM12_LSB0,
   OPERAND_UIMM20,
   OPERAND_UIMMLOG2XLEN,
   OPERAND_RVKRNUM,

diff  --git a/llvm/lib/Target/RISCV/RISCV.td b/llvm/lib/Target/RISCV/RISCV.td
index 9b36598116a11..e783ef38b4484 100644
--- a/llvm/lib/Target/RISCV/RISCV.td
+++ b/llvm/lib/Target/RISCV/RISCV.td
@@ -414,6 +414,13 @@ def HasStdExtZicboz : 
Predicate<"Subtarget->hasStdExtZicboz()">,
 AssemblerPredica

[PATCH] D117432: [RISCV] Implement support for the Zicbom and Zicboz extensions

2022-06-28 Thread Alex Bradbury via Phabricator via cfe-commits
asb added a comment.

In D117432#3599255 , @craig.topper 
wrote:

> Reverse ping. Is anything blocking this being merged?

No, thanks for the ping - now landed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117432

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


[PATCH] D124750: [MLIR] Add a utility to sort the operands of commutative ops

2022-06-28 Thread Srishti Srivastava via Phabricator via cfe-commits
srishti-pm updated this revision to Diff 440570.
srishti-pm marked 6 inline comments as done.
srishti-pm added a comment.

Addressed the final comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124750

Files:
  mlir/include/mlir/Transforms/CommutativityUtils.h
  mlir/lib/Transforms/Utils/CMakeLists.txt
  mlir/lib/Transforms/Utils/CommutativityUtils.cpp
  mlir/test/Transforms/test-commutativity-utils.mlir
  mlir/test/lib/Dialect/Test/TestOps.td
  mlir/test/lib/Transforms/CMakeLists.txt
  mlir/test/lib/Transforms/TestCommutativityUtils.cpp
  mlir/tools/mlir-opt/mlir-opt.cpp

Index: mlir/tools/mlir-opt/mlir-opt.cpp
===
--- mlir/tools/mlir-opt/mlir-opt.cpp
+++ mlir/tools/mlir-opt/mlir-opt.cpp
@@ -57,6 +57,7 @@
 void registerVectorizerTestPass();
 
 namespace test {
+void registerCommutativityUtils();
 void registerConvertCallOpPass();
 void registerInliner();
 void registerMemRefBoundCheck();
@@ -152,6 +153,7 @@
   registerVectorizerTestPass();
   registerTosaTestQuantUtilAPIPass();
 
+  mlir::test::registerCommutativityUtils();
   mlir::test::registerConvertCallOpPass();
   mlir::test::registerInliner();
   mlir::test::registerMemRefBoundCheck();
Index: mlir/test/lib/Transforms/TestCommutativityUtils.cpp
===
--- /dev/null
+++ mlir/test/lib/Transforms/TestCommutativityUtils.cpp
@@ -0,0 +1,48 @@
+//===- TestCommutativityUtils.cpp - Pass to test the commutativity utility-===//
+//
+// 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
+//
+//===--===//
+//
+// This pass tests the functionality of the commutativity utility pattern.
+//
+//===--===//
+
+#include "mlir/Transforms/CommutativityUtils.h"
+
+#include "TestDialect.h"
+#include "mlir/Pass/Pass.h"
+#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
+
+using namespace mlir;
+
+namespace {
+
+struct CommutativityUtils
+: public PassWrapper> {
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(CommutativityUtils)
+
+  StringRef getArgument() const final { return "test-commutativity-utils"; }
+  StringRef getDescription() const final {
+return "Test the functionality of the commutativity utility";
+  }
+
+  void runOnOperation() override {
+auto func = getOperation();
+auto *context = &getContext();
+
+RewritePatternSet patterns(context);
+populateCommutativityUtilsPatterns(patterns);
+
+(void)applyPatternsAndFoldGreedily(func, std::move(patterns));
+  }
+};
+} // namespace
+
+namespace mlir {
+namespace test {
+void registerCommutativityUtils() { PassRegistration(); }
+} // namespace test
+} // namespace mlir
Index: mlir/test/lib/Transforms/CMakeLists.txt
===
--- mlir/test/lib/Transforms/CMakeLists.txt
+++ mlir/test/lib/Transforms/CMakeLists.txt
@@ -1,5 +1,6 @@
 # Exclude tests from libMLIR.so
 add_mlir_library(MLIRTestTransforms
+  TestCommutativityUtils.cpp
   TestConstantFold.cpp
   TestControlFlowSink.cpp
   TestInlining.cpp
Index: mlir/test/lib/Dialect/Test/TestOps.td
===
--- mlir/test/lib/Dialect/Test/TestOps.td
+++ mlir/test/lib/Dialect/Test/TestOps.td
@@ -1162,11 +1162,21 @@
   let hasFolder = 1;
 }
 
+def TestAddIOp : TEST_Op<"addi"> {
+  let arguments = (ins I32:$op1, I32:$op2);
+  let results = (outs I32);
+}
+
 def TestCommutativeOp : TEST_Op<"op_commutative", [Commutative]> {
   let arguments = (ins I32:$op1, I32:$op2, I32:$op3, I32:$op4);
   let results = (outs I32);
 }
 
+def TestLargeCommutativeOp : TEST_Op<"op_large_commutative", [Commutative]> {
+  let arguments = (ins I32:$op1, I32:$op2, I32:$op3, I32:$op4, I32:$op5, I32:$op6, I32:$op7);
+  let results = (outs I32);
+}
+
 def TestCommutative2Op : TEST_Op<"op_commutative2", [Commutative]> {
   let arguments = (ins I32:$op1, I32:$op2);
   let results = (outs I32);
Index: mlir/test/Transforms/test-commutativity-utils.mlir
===
--- /dev/null
+++ mlir/test/Transforms/test-commutativity-utils.mlir
@@ -0,0 +1,116 @@
+// RUN: mlir-opt %s -test-commutativity-utils | FileCheck %s
+
+// CHECK-LABEL: @test_small_pattern_1
+func.func @test_small_pattern_1(%arg0 : i32) -> i32 {
+  // CHECK-NEXT: %[[ARITH_CONST:.*]] = arith.constant
+  %0 = arith.constant 45 : i32
+
+  // CHECK-NEXT: %[[TEST_ADD:.*]] = "test.addi"
+  %1 = "test.addi"(%arg0, %arg0): (i32, i32) -> i32
+
+  // CHECK-NEXT: %[[ARITH_ADD:.*]] = arith.addi
+  %2 = arith.addi %arg0, %arg0 : i32
+
+  // CHECK-NEXT: %[[ARITH_MUL:.*]] 

[PATCH] D124750: [MLIR] Add a utility to sort the operands of commutative ops

2022-06-28 Thread Srishti Srivastava via Phabricator via cfe-commits
srishti-pm added a comment.

@mehdi_amini, I have made sure that the algorithm is good in terms of both time 
and space complexity.

@Mogball, "handling attributes (e.g. cmpi slt vs cmpi sgt)" doesn't seem hard 
to me. I think this algorithm can be extended with ease to take attributes into 
account. But, I don't think that it should be a part of this revision (I 
believe you agree) because it seems like an incremental change which should be 
added only when the need arises. A new user should first get accustomed to this 
utility (and how its sorts operands with different backward slices) and then 
the utility can be extended to differentiate between backward slices containing 
ops with the same name but different attribute values.




Comment at: mlir/include/mlir/Transforms/CommutativityUtils.h:34
+/// Stores the "key" associated with a block argument or an operation.
+struct BlockArgumentOrOpKey {
+  /// Holds `BLOCK_ARGUMENT`, `NON_CONSTANT_OP`, or `CONSTANT_OP`, depending on

Mogball wrote:
> `using BlockArgumentOrOpKey = std::pair`
> 
> The default `operator<` for `std::pair` should work for you.
I have added a constructor to `BlockArgumentOrOpKey` (now renamed to 
`AncestorKey`) and thus I think this comment is obsolete now. Hope that this 
fine. Adding a constructor made the code look cleaner.



Comment at: mlir/include/mlir/Transforms/CommutativityUtils.h:226
+for (Value operand : op->getOperands()) {
+  OperandBFS *bfsOfOperand = new OperandBFS();
+  bfsOfOperand->pushAncestor(operand.getDefiningOp());

Mogball wrote:
> memory leak?
Fixed this by adding a struct called "Ancestor" which refers to either an op or 
a block argument.



Comment at: mlir/include/mlir/Transforms/CommutativityUtils.h:257
+  // smallest.
+  DenseSet smallestKeyIndices;
+  // Stores the indices of the unassigned operands whose key is the 
largest.

Mogball wrote:
> Could you not change `getIndicesOfUnassigned...` to populate two lists of 
> operands and pass these to `assignSortedPositionTo` instead of using a set to 
> track the indices. You could put the operand index inside `OperandBFS` to 
> keep track.
I think that doing this might not be a good idea. It will increase the space 
complexity unnecessarily (OperandBFS is a big structure) and not help much with 
the time complexity because the sets of the indices are expected to be small. 
At least the number of indices will be <= the total number of operands and each 
element in these sets will occupy very less space (size of `unsigned`).



Comment at: mlir/lib/Transforms/Utils/CommutativityUtils.cpp:271
+  for (Operation *operandDefOp : operandDefOps) {
+OperandBFS *bfsOfOperand = new OperandBFS();
+bfsOfOperand->pushAncestor(operandDefOp);

mehdi_amini wrote:
> Is this a leak?
> 
Fixed this by adding a struct called "Ancestor" which refers to either an op or 
a block argument.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124750

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


[PATCH] D128612: RISC-V big-endian support implementation

2022-06-28 Thread Guy Benyei via Phabricator via cfe-commits
gbenyei updated this revision to Diff 440579.
gbenyei marked 7 inline comments as done.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128612

Files:
  clang/include/clang/Basic/Attr.td
  clang/lib/Basic/Targets.cpp
  clang/lib/Basic/Targets/OSTargets.h
  clang/lib/Basic/Targets/RISCV.cpp
  clang/lib/Basic/Targets/RISCV.h
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Arch/RISCV.cpp
  clang/lib/Driver/ToolChains/BareMetal.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/FreeBSD.cpp
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/lib/Driver/ToolChains/Linux.cpp
  clang/lib/Driver/ToolChains/RISCVToolchain.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  lld/ELF/Arch/RISCV.cpp
  lld/ELF/InputFiles.cpp
  lldb/source/Utility/ArchSpec.cpp
  llvm/cmake/config.guess
  llvm/include/llvm/ADT/Triple.h
  llvm/include/llvm/Object/ELFObjectFile.h
  llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
  llvm/lib/ExecutionEngine/JITLink/ELF.cpp
  llvm/lib/ExecutionEngine/JITLink/ELF_riscv.cpp
  llvm/lib/ExecutionEngine/Orc/EPCIndirectionUtils.cpp
  llvm/lib/ExecutionEngine/Orc/IndirectionUtils.cpp
  llvm/lib/ExecutionEngine/Orc/LazyReexports.cpp
  llvm/lib/Object/RelocationResolver.cpp
  llvm/lib/Support/Triple.cpp
  llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
  llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.h
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCAsmInfo.cpp
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCTargetDesc.cpp
  llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp
  llvm/lib/Target/RISCV/RISCVTargetMachine.cpp
  llvm/lib/Target/RISCV/TargetInfo/RISCVTargetInfo.cpp
  llvm/lib/Target/RISCV/TargetInfo/RISCVTargetInfo.h
  llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
  llvm/test/tools/llvm-objcopy/ELF/binary-output-target.test
  llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
  llvm/unittests/Object/ELFObjectFileTest.cpp

Index: llvm/unittests/Object/ELFObjectFileTest.cpp
===
--- llvm/unittests/Object/ELFObjectFileTest.cpp
+++ llvm/unittests/Object/ELFObjectFileTest.cpp
@@ -186,10 +186,10 @@
 }
 
 TEST(ELFObjectFileTest, MachineTestForRISCV) {
-  std::array Formats = {"elf32-littleriscv", "elf32-littleriscv",
-  "elf64-littleriscv", "elf64-littleriscv"};
-  std::array Archs = {Triple::riscv32, Triple::riscv32,
-   Triple::riscv64, Triple::riscv64};
+  std::array Formats = {"elf32-littleriscv", "elf32-bigriscv",
+  "elf64-littleriscv", "elf64-bigriscv"};
+  std::array Archs = {Triple::riscv32, Triple::riscv32be,
+   Triple::riscv64, Triple::riscv64be};
   size_t I = 0;
   for (const DataForTest &D : generateData(ELF::EM_RISCV)) {
 checkFormatAndArch(D, Formats[I], Archs[I]);
Index: llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
===
--- llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
+++ llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
@@ -301,6 +301,8 @@
 // RISC-V
 {"elf32-littleriscv", {ELF::EM_RISCV, false, true}},
 {"elf64-littleriscv", {ELF::EM_RISCV, true, true}},
+{"elf32-bigriscv", {ELF::EM_RISCV, false, false}},
+{"elf64-bigriscv", {ELF::EM_RISCV, true, false}},
 // PowerPC
 {"elf32-powerpc", {ELF::EM_PPC, false, false}},
 {"elf32-powerpcle", {ELF::EM_PPC, false, true}},
Index: llvm/test/tools/llvm-objcopy/ELF/binary-output-target.test
===
--- llvm/test/tools/llvm-objcopy/ELF/binary-output-target.test
+++ llvm/test/tools/llvm-objcopy/ELF/binary-output-target.test
@@ -33,6 +33,12 @@
 # RUN: llvm-objcopy -I binary -O elf64-littleriscv %t.txt %t.rv64.o
 # RUN: llvm-readobj --file-headers %t.rv64.o | FileCheck %s --check-prefixes=CHECK,LE,RISCV64,64
 
+# RUN: llvm-objcopy -I binary -O elf32-bigriscv %t.txt %t.rv32.o
+# RUN: llvm-readobj --file-headers %t.rv32.o | FileCheck %s --check-prefixes=CHECK,BE,RISCV32,32
+
+# RUN: llvm-objcopy -I binary -O elf64-bigriscv %t.txt %t.rv64.o
+# RUN: llvm-readobj --file-headers %t.rv64.o | FileCheck %s --check-prefixes=CHECK,BE,RISCV64,64
+
 # RUN: llvm-objcopy -I binary -O elf32-sparc %t.txt %t.sparc.o
 # RUN: llvm-readobj --file-headers %t.sparc.o | FileCheck %s --check-prefixes=CHECK,BE,SPARC,32
 
Index: llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
===
--- llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
+++ llvm/lib/T

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

2022-06-28 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added inline comments.
Herald added a subscriber: steakhal.



Comment at: clang/tools/libclang/CIndex.cpp:3452
   continue;
-
-if (Visit(MakeCursorVariableRef(C->getCapturedVar(), C->getLocation(),
-TU)))
+// TODO: hamdle structured bindings here ?
+if (!isa(C->getCapturedVar()))

Note to self: typo


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


[PATCH] D128351: [clang] missing outer template levels when checking template constraints

2022-06-28 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

So I don't think this is the right fix for this... But I DID check and see that 
the test case seems to be fixed here: https://reviews.llvm.org/D126907 , which 
does a lot of rework for this sort of thing.

That patch is expected to be complete/ready for submission in the 'near 
future', but I'm still working through 1 more issue.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128351

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


[PATCH] D128726: [RISCV][NFC] Move static global variables into static variable in function.

2022-06-28 Thread Kito Cheng via Phabricator via cfe-commits
kito-cheng created this revision.
Herald added subscribers: sunshaoce, VincentWu, luke957, vkmr, frasercrmck, 
evandro, luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, 
jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, 
zzheng, jrtc27, shiva0217, niosHD, sabuasal, simoncook, johnrusso, rbar, asb, 
arichardson.
Herald added a project: All.
kito-cheng requested review of this revision.
Herald added subscribers: cfe-commits, pcwang-thead, eopXD, MaskRay.
Herald added a project: clang.

It's violate coding guideline in LLVM coding standard[1], and the
variable seems only used to cache the query result, so this could be
just a static variable within function.

[1] https://llvm.org/docs/CodingStandards.html#do-not-use-static-constructors


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D128726

Files:
  clang/lib/Support/RISCVVIntrinsicUtils.cpp


Index: clang/lib/Support/RISCVVIntrinsicUtils.cpp
===
--- clang/lib/Support/RISCVVIntrinsicUtils.cpp
+++ clang/lib/Support/RISCVVIntrinsicUtils.cpp
@@ -31,10 +31,6 @@
 const PrototypeDescriptor PrototypeDescriptor::Vector =
 PrototypeDescriptor(BaseTypeModifier::Vector);
 
-// Concat BasicType, LMUL and Proto as key
-static std::unordered_map LegalTypes;
-static std::set IllegalTypes;
-
 
//===--===//
 // Type implementation
 
//===--===//
@@ -822,6 +818,9 @@
 
 Optional RVVType::computeType(BasicType BT, int Log2LMUL,
   PrototypeDescriptor Proto) {
+  // Concat BasicType, LMUL and Proto as key
+  static std::unordered_map LegalTypes;
+  static std::set IllegalTypes;
   uint64_t Idx = computeRVVTypeHashValue(BT, Log2LMUL, Proto);
   // Search first
   auto It = LegalTypes.find(Idx);


Index: clang/lib/Support/RISCVVIntrinsicUtils.cpp
===
--- clang/lib/Support/RISCVVIntrinsicUtils.cpp
+++ clang/lib/Support/RISCVVIntrinsicUtils.cpp
@@ -31,10 +31,6 @@
 const PrototypeDescriptor PrototypeDescriptor::Vector =
 PrototypeDescriptor(BaseTypeModifier::Vector);
 
-// Concat BasicType, LMUL and Proto as key
-static std::unordered_map LegalTypes;
-static std::set IllegalTypes;
-
 //===--===//
 // Type implementation
 //===--===//
@@ -822,6 +818,9 @@
 
 Optional RVVType::computeType(BasicType BT, int Log2LMUL,
   PrototypeDescriptor Proto) {
+  // Concat BasicType, LMUL and Proto as key
+  static std::unordered_map LegalTypes;
+  static std::set IllegalTypes;
   uint64_t Idx = computeRVVTypeHashValue(BT, Log2LMUL, Proto);
   // Search first
   auto It = LegalTypes.find(Idx);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D113107: Support of expression granularity for _Float16.

2022-06-28 Thread Zahira Ammarguellat via Phabricator via cfe-commits
zahiraam marked an inline comment as done.
zahiraam added a comment.

In D113107#3606106 , @rjmccall wrote:

> In D113107#3606094 , @zahiraam 
> wrote:
>
>> In D113107#3605797 , @rjmccall 
>> wrote:
>>
>>> I think on balance the right thing to do is probably to add an alternative 
>>> to `-fexcess-precision`, like `-fexcess-precision=none`.  We can default to 
>>> `-fexcess-precision=standard` and treat `-fexcess-precision=fast` as an 
>>> alias for `standard` for now.
>>
>> In 
>> https://gcc.gnu.org/onlinedocs/gcc-4.8.2/gcc/Optimize-Options.html#index-ffloat-store-900
>>  ,  it looks like when compiling C, the default is 
>> -fexcess-precision=standard which would align with this implementation and 
>> our default too. So I think we could use the same name for the option. 
>> -fexcess-precision=none corresponds to the current behavior.
>> -fexcess-precision=standard = -fexcess-precision=fast corresponds to this 
>> implementation.
>> Agreed?
>
> Since you're not landing this option right now anyway, do you mind broaching 
> this with the GCC folks, just to be good neighbors?  You can just say that 
> (1) Clang is looking for a way to request operation-by-operation lowering, 
> (2) it feels like `-fexcess-precision` is the right option to add that to, 
> (3) we don't want to tread on toes by adding an alternative to "their" option 
> without talking to them first, and (4) what do they think about "none"?

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106117


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

https://reviews.llvm.org/D113107

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


[PATCH] D128697: [clang-tidy] Add new check `bugprone-unhandled-exception-at-sto`

2022-06-28 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added a comment.

I think will be good idea to make check more generic and allow user-defined 
list of unsafe functions.




Comment at: clang-tools-extra/docs/ReleaseNotes.rst:135
 
+- New :doc:`bugprone-unhandled-exception-at-sto
+  ` check.

Please keep entries in alphabetical order in section.



Comment at: clang-tools-extra/docs/ReleaseNotes.rst:138
+
+  Finds calls to ``stoi`` and ``stod`` families of functions with missing 
exception handler for ``std::invalid_argument`` and ``std::out_of_range``.
+

Please follow 80 characters limit.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/bugprone/unhandled-exception-at-sto.rst:6
+
+Finds calls to ``stoi`` and ``stof`` families of functions with missing 
exception handler for ``std::invalid_argument`` and ``std::out_of_range``.
+

Ditto.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/bugprone/unhandled-exception-at-sto.rst:15
+
+Calls to ``stoi`` and ``stof`` families of functions can throw exceptions of 
type ``std::invalid_argument`` and ``std::out_of_range`` that should be handled 
by the code.

Ditto.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128697

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


[PATCH] D124690: [clangd] add inlay hints for std::forward-ed parameter packs

2022-06-28 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.
This revision is now accepted and ready to land.

Sorry about the delay. This is complicated stuff and every time I put it down 
for a day I forget how it works!
Thanks for your hard work here.

I have some more suggestions but hopefully fairly mechanical.
Feel free to land once you're done, or send it back over to Nathan or I to 
commit.




Comment at: clang-tools-extra/clangd/AST.cpp:677
+
+// Checks if the template parameter declaration is a type parameter pack
+bool isTemplateTypeParameterPack(NamedDecl *D) {

nit: this comment doesn't really say anything that the method name doesn't say 
already.

Maybe replace with an example like "returns true for `X` in `template 
 int m;`"



Comment at: clang-tools-extra/clangd/AST.cpp:680
+  if (const auto *TTPD = dyn_cast(D)) {
+const auto *TTPT = TTPD->getTypeForDecl()->castAs();
+return TTPT->isParameterPack();

TTPD->isParameterPack() does the same thing with less code



Comment at: clang-tools-extra/clangd/AST.cpp:689
+const TemplateTypeParmType *
+getPackTemplateParameter(const FunctionDecl *Callee) {
+  if (const auto *TemplateDecl = Callee->getPrimaryTemplate()) {

it seems confusing and unneccesary to use the same name for the two versions of 
this function. The name applies to both, but they don't really do the same 
thing.

Maybe call this one getFunctionPackType and the other getUnderylingPackType?
(not get*TemplateParameter as they return a type, not the parameter decl)



Comment at: clang-tools-extra/clangd/AST.cpp:690
+getPackTemplateParameter(const FunctionDecl *Callee) {
+  if (const auto *TemplateDecl = Callee->getPrimaryTemplate()) {
+auto TemplateParams = TemplateDecl->getTemplateParameters()->asArray();

This is doing something pretty strange if Callee is a function template 
specialization.

It's not clear to me whether this function should be handling that case (which 
AFAICS it doesn't, but could inspect the specialization kind), or whether 
resolveForwardingParameters is responsible for not calling this function in 
that case (in which case we should probably have an assert here).

Can you also add a test case that function template specialization doesn't 
confuse us? i.e. it should return the parmvardecls from the specialization's 
definition.



Comment at: clang-tools-extra/clangd/AST.cpp:720
+
+class ForwardingCallVisitor
+: public RecursiveASTVisitor {

This class could use a high-level comment explaining what it does.

e.g.
```
This visitor walks over the body of an instantiated function template.
The template accepts a parameter pack and the visitor records whether
the pack parameters were forwarded to another call. For example, given:

template 
auto make_unique(Args..args) {
  return unique_ptr(new T(args...));
}

When called as `make_unique(2, 'x')` this yields a function
`make_unique` with two parameters.
The visitor records that those two parameters are forwarded to the
`constructor std::string(int, char);`.

This information is recorded in the `ForwardingInfo` (in general,
more complicated scenarios are also possible).
```



Comment at: clang-tools-extra/clangd/AST.h:212
+/// reference to one (e.g. `Args&...` or `Args&&...`).
+bool isExpandedParameterPack(const ParmVarDecl *D);
+

nit: I think isExpanded**From**ParameterPack might be clearer, up to you



Comment at: clang-tools-extra/clangd/InlayHints.cpp:398
+auto Params = resolveForwardingParameters(Callee);
+// We are only interested in expanded arguments with corresponding
+// parameters.

I can't understand what this comment is saying, can you rephrase it or provide 
an example?

From looking at the code, I'm guessing something like:
"If we're passing a parameter pack into this call, we need to give up matching 
arguments to parameters at that point as we don't know how long it is".

---

I think the interaction between getExpandedArgCount and chooseParameterNames is 
unclear and brittle here. (i.e. the invariant that 
`getExpandedArgCount(Args).size() < chooseParameterNames(Params).size()` is 
very non-local)

I'd suggest writing this more directly as:
```
for (I = 0; I < ParameterNames.size() && I < Args.size(); ++I) {
  // ... explanation ...
  if (isa(Args[I]))
break;

  // ... generate param hint ...
}
```



Comment at: clang-tools-extra/clangd/InlayHints.cpp:483
+   !Type.getNonReferenceType().isConstQualified() &&
+   !isExpandedParameterPack(Param);
   }

why is this check needed if we already decline to provide a name for the 
parameter on line 534 in chooseParameterNames?



Comment at: clang-tools-extra/clangd/InlayHints.cpp:541
+if (SimpleName.empty()) {
+  if (a

[PATCH] D128687: [pseudo] Allow mixed designated/undesignated init lists.

2022-06-28 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/pseudo/lib/cxx.bnf:468
 designator := . IDENTIFIER
+designator := [ expression ]
 expr-or-braced-init-list := expression

I think this is the syntax of gnu extension, can we add a trailing comment for 
this rule?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128687

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


[PATCH] D128048: Add a new clang option "-ftime-trace-path"

2022-06-28 Thread dongjunduo via Phabricator via cfe-commits
dongjunduo added inline comments.



Comment at: clang/include/clang/Driver/Options.td:2819
"'per-pass-run': one report for each pass invocation">;
 def ftime_trace : Flag<["-"], "ftime-trace">, Group,
   HelpText<"Turn on time profiler. Generates JSON file based on output 
filename.">,

@MaskRay @jamieschmeiser May I change the option "-ftime-trace" from a "Flag" 
type to a "Joined" type?

I have noticed that lld's option "[[ 
https://reviews.llvm.org/rG661c089a402e0d41a28c94fab35d85c8ef90747e | 
-ftime-trace-file ]]" is used to specify the output file name. It must be 
specified simultaneously with "-ftime-trace". 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128048

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


[PATCH] D128687: [pseudo] Allow mixed designated/undesignated init lists.

2022-06-28 Thread Sam McCall via Phabricator via cfe-commits
sammccall marked an inline comment as done.
sammccall added inline comments.



Comment at: clang-tools-extra/pseudo/lib/cxx.bnf:468
 designator := . IDENTIFIER
+designator := [ expression ]
 expr-or-braced-init-list := expression

hokein wrote:
> I think this is the syntax of gnu extension, can we add a trailing comment 
> for this rule?
Done - these are actually also legal in C. Also added to commit message.

(I don't love using trailing comments in this file - they feel hard to spot).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128687

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


[clang-tools-extra] 8cf2858 - [pseudo] Allow mixed designated/undesignated init lists.

2022-06-28 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2022-06-28T15:45:41+02:00
New Revision: 8cf28585a40311163a08840beee035097638d41d

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

LOG: [pseudo] Allow mixed designated/undesignated init lists.

This isn't allowed by the standard grammar but is allowed in C, and clang/GCC
permit it as an extension.
It avoids the need to determine which type of list we have in error-recovery.

While here, also support array index designators `{ [4]=1 }` which are
also legal in C, and common extensions in C++.

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

Added: 
clang-tools-extra/pseudo/test/cxx/mixed-designator.cpp

Modified: 
clang-tools-extra/pseudo/lib/cxx.bnf

Removed: 




diff  --git a/clang-tools-extra/pseudo/lib/cxx.bnf 
b/clang-tools-extra/pseudo/lib/cxx.bnf
index ec05af94c0269..aa243db6c5b40 100644
--- a/clang-tools-extra/pseudo/lib/cxx.bnf
+++ b/clang-tools-extra/pseudo/lib/cxx.bnf
@@ -158,7 +158,10 @@ postfix-expression := REINTERPRET_CAST < type-id > ( 
expression )
 postfix-expression := CONST_CAST < type-id > ( expression )
 postfix-expression := TYPEID ( expression )
 postfix-expression := TYPEID ( type-id )
-expression-list := initializer-list
+#! Standard defines expression-list in terms of initializer-list, but our
+#  initializer-list allows designators.
+expression-list := initializer-clause ..._opt
+expression-list := expression-list , initializer-clause ..._opt
 # expr.unary
 unary-expression := postfix-expression
 unary-expression := unary-operator cast-expression
@@ -453,15 +456,17 @@ brace-or-equal-initializer := = initializer-clause
 brace-or-equal-initializer := braced-init-list
 initializer-clause := assignment-expression
 initializer-clause := braced-init-list
+#! Allow mixed designated/non-designated init-list.
+# This is standard C, and accepted by clang and others as an extension.
 braced-init-list := { initializer-list ,_opt }
-braced-init-list := { designated-initializer-list ,_opt }
 braced-init-list := { }
-initializer-list := initializer-clause ..._opt
-initializer-list := initializer-list , initializer-clause ..._opt
-designated-initializer-list := designated-initializer-clause
-designated-initializer-list := designated-initializer-list , 
designated-initializer-clause
-designated-initializer-clause := designator brace-or-equal-initializer
+initializer-list := initializer-list-item ..._opt
+initializer-list := initializer-list , initializer-list-item ..._opt
+initializer-list-item := initializer-clause
+initializer-list-item := designator brace-or-equal-initializer
 designator := . IDENTIFIER
+#! Array designators are legal in C, and a common extension in C++.
+designator := [ expression ]
 expr-or-braced-init-list := expression
 expr-or-braced-init-list := braced-init-list
 # dcl.fct

diff  --git a/clang-tools-extra/pseudo/test/cxx/mixed-designator.cpp 
b/clang-tools-extra/pseudo/test/cxx/mixed-designator.cpp
new file mode 100644
index 0..ec5683905
--- /dev/null
+++ b/clang-tools-extra/pseudo/test/cxx/mixed-designator.cpp
@@ -0,0 +1,27 @@
+// RUN: clang-pseudo -grammar=%cxx-bnf-file -source=%s --print-forest | 
FileCheck %s
+// FIXME: tighten CHECK to CHECK-NEXT once numeric literals are unambiguous.
+auto x = { 1, .f = 2, [c]{3} };
+// CHECK:  initializer-clause~braced-init-list
+// CHECK-NEXT: ├─{ := tok[3]
+// CHECK-NEXT: ├─initializer-list
+// CHECK-NEXT: │ ├─initializer-list
+// CHECK-NEXT: │ │ ├─initializer-list~literal
+// CHECK:  │ │ ├─, := tok[5]
+// CHECK-NEXT: │ │ └─initializer-list-item
+// CHECK-NEXT: │ │   ├─designator
+// CHECK-NEXT: │ │   │ ├─. := tok[6]
+// CHECK-NEXT: │ │   │ └─IDENTIFIER := tok[7]
+// CHECK-NEXT: │ │   └─brace-or-equal-initializer
+// CHECK-NEXT: │ │ ├─= := tok[8]
+// CHECK-NEXT: │ │ └─initializer-clause~literal
+// CHECK:  │ ├─, := tok[10]
+// CHECK-NEXT: │ └─initializer-list-item
+// CHECK-NEXT: │   ├─designator
+// CHECK-NEXT: │   │ ├─[ := tok[11]
+// CHECK-NEXT: │   │ ├─expression~IDENTIFIER := tok[12]
+// CHECK-NEXT: │   │ └─] := tok[13]
+// CHECK-NEXT: │   └─brace-or-equal-initializer~braced-init-list
+// CHECK-NEXT: │ ├─{ := tok[14]
+// CHECK-NEXT: │ ├─initializer-list~literal
+// CHECK:  │ └─} := tok[16]
+// CHECK-NEXT: └─} := tok[17]



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


[PATCH] D128687: [pseudo] Allow mixed designated/undesignated init lists.

2022-06-28 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
sammccall marked an inline comment as done.
Closed by commit rG8cf28585a403: [pseudo] Allow mixed designated/undesignated 
init lists. (authored by sammccall).

Changed prior to commit:
  https://reviews.llvm.org/D128687?vs=440426&id=440599#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128687

Files:
  clang-tools-extra/pseudo/lib/cxx.bnf
  clang-tools-extra/pseudo/test/cxx/mixed-designator.cpp


Index: clang-tools-extra/pseudo/test/cxx/mixed-designator.cpp
===
--- /dev/null
+++ clang-tools-extra/pseudo/test/cxx/mixed-designator.cpp
@@ -0,0 +1,27 @@
+// RUN: clang-pseudo -grammar=%cxx-bnf-file -source=%s --print-forest | 
FileCheck %s
+// FIXME: tighten CHECK to CHECK-NEXT once numeric literals are unambiguous.
+auto x = { 1, .f = 2, [c]{3} };
+// CHECK:  initializer-clause~braced-init-list
+// CHECK-NEXT: ├─{ := tok[3]
+// CHECK-NEXT: ├─initializer-list
+// CHECK-NEXT: │ ├─initializer-list
+// CHECK-NEXT: │ │ ├─initializer-list~literal
+// CHECK:  │ │ ├─, := tok[5]
+// CHECK-NEXT: │ │ └─initializer-list-item
+// CHECK-NEXT: │ │   ├─designator
+// CHECK-NEXT: │ │   │ ├─. := tok[6]
+// CHECK-NEXT: │ │   │ └─IDENTIFIER := tok[7]
+// CHECK-NEXT: │ │   └─brace-or-equal-initializer
+// CHECK-NEXT: │ │ ├─= := tok[8]
+// CHECK-NEXT: │ │ └─initializer-clause~literal
+// CHECK:  │ ├─, := tok[10]
+// CHECK-NEXT: │ └─initializer-list-item
+// CHECK-NEXT: │   ├─designator
+// CHECK-NEXT: │   │ ├─[ := tok[11]
+// CHECK-NEXT: │   │ ├─expression~IDENTIFIER := tok[12]
+// CHECK-NEXT: │   │ └─] := tok[13]
+// CHECK-NEXT: │   └─brace-or-equal-initializer~braced-init-list
+// CHECK-NEXT: │ ├─{ := tok[14]
+// CHECK-NEXT: │ ├─initializer-list~literal
+// CHECK:  │ └─} := tok[16]
+// CHECK-NEXT: └─} := tok[17]
Index: clang-tools-extra/pseudo/lib/cxx.bnf
===
--- clang-tools-extra/pseudo/lib/cxx.bnf
+++ clang-tools-extra/pseudo/lib/cxx.bnf
@@ -158,7 +158,10 @@
 postfix-expression := CONST_CAST < type-id > ( expression )
 postfix-expression := TYPEID ( expression )
 postfix-expression := TYPEID ( type-id )
-expression-list := initializer-list
+#! Standard defines expression-list in terms of initializer-list, but our
+#  initializer-list allows designators.
+expression-list := initializer-clause ..._opt
+expression-list := expression-list , initializer-clause ..._opt
 # expr.unary
 unary-expression := postfix-expression
 unary-expression := unary-operator cast-expression
@@ -453,15 +456,17 @@
 brace-or-equal-initializer := braced-init-list
 initializer-clause := assignment-expression
 initializer-clause := braced-init-list
+#! Allow mixed designated/non-designated init-list.
+# This is standard C, and accepted by clang and others as an extension.
 braced-init-list := { initializer-list ,_opt }
-braced-init-list := { designated-initializer-list ,_opt }
 braced-init-list := { }
-initializer-list := initializer-clause ..._opt
-initializer-list := initializer-list , initializer-clause ..._opt
-designated-initializer-list := designated-initializer-clause
-designated-initializer-list := designated-initializer-list , 
designated-initializer-clause
-designated-initializer-clause := designator brace-or-equal-initializer
+initializer-list := initializer-list-item ..._opt
+initializer-list := initializer-list , initializer-list-item ..._opt
+initializer-list-item := initializer-clause
+initializer-list-item := designator brace-or-equal-initializer
 designator := . IDENTIFIER
+#! Array designators are legal in C, and a common extension in C++.
+designator := [ expression ]
 expr-or-braced-init-list := expression
 expr-or-braced-init-list := braced-init-list
 # dcl.fct


Index: clang-tools-extra/pseudo/test/cxx/mixed-designator.cpp
===
--- /dev/null
+++ clang-tools-extra/pseudo/test/cxx/mixed-designator.cpp
@@ -0,0 +1,27 @@
+// RUN: clang-pseudo -grammar=%cxx-bnf-file -source=%s --print-forest | FileCheck %s
+// FIXME: tighten CHECK to CHECK-NEXT once numeric literals are unambiguous.
+auto x = { 1, .f = 2, [c]{3} };
+// CHECK:  initializer-clause~braced-init-list
+// CHECK-NEXT: ├─{ := tok[3]
+// CHECK-NEXT: ├─initializer-list
+// CHECK-NEXT: │ ├─initializer-list
+// CHECK-NEXT: │ │ ├─initializer-list~literal
+// CHECK:  │ │ ├─, := tok[5]
+// CHECK-NEXT: │ │ └─initializer-list-item
+// CHECK-NEXT: │ │   ├─designator
+// CHECK-NEXT: │ │   │ ├─. := tok[6]
+// CHECK-NEXT: │ │   │ └─IDENTIFIER := tok[7]
+// CHECK-NEXT: │ │   └─brace-or-equal-initializer
+// CHECK-NEXT: │ │ ├─= := tok[8]
+// CHECK-NEXT: │ │ └─initializer-clause~literal
+// CHECK:  │ ├

[clang-tools-extra] aacefc8 - [pseudo] Simplify/loosen the grammar around lambda captures.

2022-06-28 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2022-06-28T15:56:12+02:00
New Revision: aacefc817d9385835db5b5e30a21687ddb4f3f93

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

LOG: [pseudo] Simplify/loosen the grammar around lambda captures.

Treat captures as a uniform list, rather than default-captures being special
snowflakes that may only appear at the start.

This accepts a larger set of (incorrect) code, and simplifies error-handling
by making this fit into the usual homogeneous-list pattern.

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

Added: 
clang-tools-extra/pseudo/test/cxx/capture-list.cpp

Modified: 
clang-tools-extra/pseudo/lib/cxx.bnf

Removed: 




diff  --git a/clang-tools-extra/pseudo/lib/cxx.bnf 
b/clang-tools-extra/pseudo/lib/cxx.bnf
index aa243db6c5b40..d6f292d0ee246 100644
--- a/clang-tools-extra/pseudo/lib/cxx.bnf
+++ b/clang-tools-extra/pseudo/lib/cxx.bnf
@@ -76,17 +76,17 @@ nested-name-specifier := nested-name-specifier IDENTIFIER ::
 nested-name-specifier := nested-name-specifier TEMPLATE_opt simple-template-id 
::
 lambda-expression := lambda-introducer lambda-declarator_opt compound-statement
 lambda-expression := lambda-introducer < template-parameter-list > 
requires-clause_opt lambda-declarator_opt compound-statement
-lambda-introducer := [ lambda-capture_opt ]
+#! We allow a capture-default to appear anywhere in a capture-list.
+# This simplifies the grammar and error recovery.
+lambda-introducer := [ capture-list_opt ]
 lambda-declarator := ( parameter-declaration-clause_opt ) 
decl-specifier-seq_opt noexcept-specifier_opt trailing-return-type_opt 
requires-clause_opt
-lambda-capture := capture-default
-lambda-capture := capture-list
-lambda-capture := capture-default , capture-list
-capture-default := &
-capture-default := =
 capture-list := capture
 capture-list := capture-list , capture
+capture := capture-default
 capture := simple-capture
 capture := init-capture
+capture-default := &
+capture-default := =
 simple-capture := IDENTIFIER ..._opt
 simple-capture := & IDENTIFIER ..._opt
 simple-capture := THIS

diff  --git a/clang-tools-extra/pseudo/test/cxx/capture-list.cpp 
b/clang-tools-extra/pseudo/test/cxx/capture-list.cpp
new file mode 100644
index 0..8659a6acae809
--- /dev/null
+++ b/clang-tools-extra/pseudo/test/cxx/capture-list.cpp
@@ -0,0 +1,23 @@
+// RUN: clang-pseudo -grammar=%cxx-bnf-file -source=%s --print-forest | 
FileCheck %s
+// We loosely allow capture defaults in any position/multiple times.
+auto lambda = [&, &foo, bar(x), =]{};
+// CHECK:  lambda-introducer := [ capture-list ]
+// CHECK-NEXT: ├─[
+// CHECK-NEXT: ├─capture-list
+// CHECK-NEXT: │ ├─capture-list
+// CHECK-NEXT: │ │ ├─capture-list
+// CHECK-NEXT: │ │ │ ├─capture-list~& := tok[4]
+// CHECK-NEXT: │ │ │ ├─,
+// CHECK-NEXT: │ │ │ └─capture~simple-capture
+// CHECK-NEXT: │ │ │   ├─&
+// CHECK-NEXT: │ │ │   └─IDENTIFIER := tok[7]
+// CHECK-NEXT: │ │ ├─,
+// CHECK-NEXT: │ │ └─capture~init-capture
+// CHECK-NEXT: │ │   ├─IDENTIFIER := tok[9]
+// CHECK-NEXT: │ │   └─initializer := ( expression-list )
+// CHECK-NEXT: │ │ ├─(
+// CHECK-NEXT: │ │ ├─expression-list~IDENTIFIER := tok[11]
+// CHECK-NEXT: │ │ └─)
+// CHECK-NEXT: │ ├─,
+// CHECK-NEXT: │ └─capture~=
+// CHECK-NEXT: └─]



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


[PATCH] D128708: [pseudo] Simplify/loosen the grammar around lambda captures.

2022-06-28 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGaacefc817d93: [pseudo] Simplify/loosen the grammar around 
lambda captures. (authored by sammccall).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128708

Files:
  clang-tools-extra/pseudo/lib/cxx.bnf
  clang-tools-extra/pseudo/test/cxx/capture-list.cpp


Index: clang-tools-extra/pseudo/test/cxx/capture-list.cpp
===
--- /dev/null
+++ clang-tools-extra/pseudo/test/cxx/capture-list.cpp
@@ -0,0 +1,23 @@
+// RUN: clang-pseudo -grammar=%cxx-bnf-file -source=%s --print-forest | 
FileCheck %s
+// We loosely allow capture defaults in any position/multiple times.
+auto lambda = [&, &foo, bar(x), =]{};
+// CHECK:  lambda-introducer := [ capture-list ]
+// CHECK-NEXT: ├─[
+// CHECK-NEXT: ├─capture-list
+// CHECK-NEXT: │ ├─capture-list
+// CHECK-NEXT: │ │ ├─capture-list
+// CHECK-NEXT: │ │ │ ├─capture-list~& := tok[4]
+// CHECK-NEXT: │ │ │ ├─,
+// CHECK-NEXT: │ │ │ └─capture~simple-capture
+// CHECK-NEXT: │ │ │   ├─&
+// CHECK-NEXT: │ │ │   └─IDENTIFIER := tok[7]
+// CHECK-NEXT: │ │ ├─,
+// CHECK-NEXT: │ │ └─capture~init-capture
+// CHECK-NEXT: │ │   ├─IDENTIFIER := tok[9]
+// CHECK-NEXT: │ │   └─initializer := ( expression-list )
+// CHECK-NEXT: │ │ ├─(
+// CHECK-NEXT: │ │ ├─expression-list~IDENTIFIER := tok[11]
+// CHECK-NEXT: │ │ └─)
+// CHECK-NEXT: │ ├─,
+// CHECK-NEXT: │ └─capture~=
+// CHECK-NEXT: └─]
Index: clang-tools-extra/pseudo/lib/cxx.bnf
===
--- clang-tools-extra/pseudo/lib/cxx.bnf
+++ clang-tools-extra/pseudo/lib/cxx.bnf
@@ -76,17 +76,17 @@
 nested-name-specifier := nested-name-specifier TEMPLATE_opt simple-template-id 
::
 lambda-expression := lambda-introducer lambda-declarator_opt compound-statement
 lambda-expression := lambda-introducer < template-parameter-list > 
requires-clause_opt lambda-declarator_opt compound-statement
-lambda-introducer := [ lambda-capture_opt ]
+#! We allow a capture-default to appear anywhere in a capture-list.
+# This simplifies the grammar and error recovery.
+lambda-introducer := [ capture-list_opt ]
 lambda-declarator := ( parameter-declaration-clause_opt ) 
decl-specifier-seq_opt noexcept-specifier_opt trailing-return-type_opt 
requires-clause_opt
-lambda-capture := capture-default
-lambda-capture := capture-list
-lambda-capture := capture-default , capture-list
-capture-default := &
-capture-default := =
 capture-list := capture
 capture-list := capture-list , capture
+capture := capture-default
 capture := simple-capture
 capture := init-capture
+capture-default := &
+capture-default := =
 simple-capture := IDENTIFIER ..._opt
 simple-capture := & IDENTIFIER ..._opt
 simple-capture := THIS


Index: clang-tools-extra/pseudo/test/cxx/capture-list.cpp
===
--- /dev/null
+++ clang-tools-extra/pseudo/test/cxx/capture-list.cpp
@@ -0,0 +1,23 @@
+// RUN: clang-pseudo -grammar=%cxx-bnf-file -source=%s --print-forest | FileCheck %s
+// We loosely allow capture defaults in any position/multiple times.
+auto lambda = [&, &foo, bar(x), =]{};
+// CHECK:  lambda-introducer := [ capture-list ]
+// CHECK-NEXT: ├─[
+// CHECK-NEXT: ├─capture-list
+// CHECK-NEXT: │ ├─capture-list
+// CHECK-NEXT: │ │ ├─capture-list
+// CHECK-NEXT: │ │ │ ├─capture-list~& := tok[4]
+// CHECK-NEXT: │ │ │ ├─,
+// CHECK-NEXT: │ │ │ └─capture~simple-capture
+// CHECK-NEXT: │ │ │   ├─&
+// CHECK-NEXT: │ │ │   └─IDENTIFIER := tok[7]
+// CHECK-NEXT: │ │ ├─,
+// CHECK-NEXT: │ │ └─capture~init-capture
+// CHECK-NEXT: │ │   ├─IDENTIFIER := tok[9]
+// CHECK-NEXT: │ │   └─initializer := ( expression-list )
+// CHECK-NEXT: │ │ ├─(
+// CHECK-NEXT: │ │ ├─expression-list~IDENTIFIER := tok[11]
+// CHECK-NEXT: │ │ └─)
+// CHECK-NEXT: │ ├─,
+// CHECK-NEXT: │ └─capture~=
+// CHECK-NEXT: └─]
Index: clang-tools-extra/pseudo/lib/cxx.bnf
===
--- clang-tools-extra/pseudo/lib/cxx.bnf
+++ clang-tools-extra/pseudo/lib/cxx.bnf
@@ -76,17 +76,17 @@
 nested-name-specifier := nested-name-specifier TEMPLATE_opt simple-template-id ::
 lambda-expression := lambda-introducer lambda-declarator_opt compound-statement
 lambda-expression := lambda-introducer < template-parameter-list > requires-clause_opt lambda-declarator_opt compound-statement
-lambda-introducer := [ lambda-capture_opt ]
+#! We allow a capture-default to appear anywhere in a capture-list.
+# This simplifies the grammar and error recovery.
+lambda-introducer := [ capture-list_opt ]
 lambda-declarator := ( parameter-declaration-clause_opt ) decl-specifier-seq_opt noexcept-specifier

[clang-tools-extra] 241557f - [pseudo] Move cxx grammar into the cxx/ directory. NFC

2022-06-28 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2022-06-28T16:02:10+02:00
New Revision: 241557fb0600fcef67bdd0698fbbd2fb9a3459e2

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

LOG: [pseudo] Move cxx grammar into the cxx/ directory. NFC

Added: 
clang-tools-extra/pseudo/lib/cxx/cxx.bnf

Modified: 
clang-tools-extra/pseudo/include/CMakeLists.txt
clang-tools-extra/pseudo/test/lit.local.cfg

Removed: 
clang-tools-extra/pseudo/lib/cxx.bnf



diff  --git a/clang-tools-extra/pseudo/include/CMakeLists.txt 
b/clang-tools-extra/pseudo/include/CMakeLists.txt
index 92259594bce1f..11a3e47157ead 100644
--- a/clang-tools-extra/pseudo/include/CMakeLists.txt
+++ b/clang-tools-extra/pseudo/include/CMakeLists.txt
@@ -1,5 +1,5 @@
 # The cxx.bnf grammar file
-set(cxx_bnf ${CMAKE_CURRENT_SOURCE_DIR}/../lib/cxx.bnf)
+set(cxx_bnf ${CMAKE_CURRENT_SOURCE_DIR}/../lib/cxx/cxx.bnf)
 
 set(CLANG_PSEUDO_GEN "clang-pseudo-gen" CACHE
   STRING "Host clang-pseudo-gen executable. Saves building if 
cross-compiling.")

diff  --git a/clang-tools-extra/pseudo/lib/cxx.bnf 
b/clang-tools-extra/pseudo/lib/cxx/cxx.bnf
similarity index 100%
rename from clang-tools-extra/pseudo/lib/cxx.bnf
rename to clang-tools-extra/pseudo/lib/cxx/cxx.bnf

diff  --git a/clang-tools-extra/pseudo/test/lit.local.cfg 
b/clang-tools-extra/pseudo/test/lit.local.cfg
index 899b7e159a7f4..b5969c8874698 100644
--- a/clang-tools-extra/pseudo/test/lit.local.cfg
+++ b/clang-tools-extra/pseudo/test/lit.local.cfg
@@ -1,2 +1,2 @@
-cxx_bnf_file = os.path.join(config.clang_pseudo_source_dir, 'lib', 'cxx.bnf')
+cxx_bnf_file = os.path.join(config.clang_pseudo_source_dir, 'lib', 'cxx', 
'cxx.bnf')
 config.substitutions.append(('%cxx-bnf-file', cxx_bnf_file))



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


[PATCH] D128645: Update developer policy.

2022-06-28 Thread Edd Barrett via Phabricator via cfe-commits
vext01 added inline comments.



Comment at: llvm/docs/DeveloperPolicy.rst:87
 
-#. Patches should be made with ``git format-patch``, or similar (see special
-   commands for `Requesting Phabricator review via the web interface
-   `_ ). If you use a
-   different tool, make sure it uses the ``diff -u`` format and that it
-   doesn't contain clutter which makes it hard to read.
-
-Once your patch is ready, submit it by emailing it to the appropriate project's
-commit mailing list (or commit it directly if applicable). Alternatively, some
-patches get sent to the project's development list or component of the LLVM bug
-tracker, but the commit list is the primary place for reviews and should
-generally be preferred.
-
-When sending a patch to a mailing list, it is a good idea to send it as an
-*attachment* to the message, not embedded into the text of the message.  This
-ensures that your mailer will not mangle the patch when it sends it (e.g. by
-making whitespace changes or by wrapping lines).
-
-*For Thunderbird users:* Before submitting a patch, please open *Preferences >
-Advanced > General > Config Editor*, find the key
-``mail.content_disposition_type``, and set its value to ``1``. Without this
-setting, Thunderbird sends your attachment using ``Content-Disposition: 
inline``
-rather than ``Content-Disposition: attachment``. Apple Mail gamely displays 
such
-a file inline, making it difficult to work with for reviewers using that
-program.
-
-When submitting patches, please do not add confidentiality or non-disclosure
-notices to the patches themselves.  These notices conflict with the LLVM
-licensing terms and may result in your contribution being excluded.
+#. Patches should be unified diffs with "infinte context" (i.e. using something
+   like `git diff -U 99 main`).

aaron.ballman wrote:
> vext01 wrote:
> > aaron.ballman wrote:
> > > Changing this would require an RFC to see if the community wants to get 
> > > rid of our requirement that patches be formatted. Personally, I'd be 
> > > opposed to such a change; I think this should be kept.
> > Is there confusion between `git format-patch` and `git clang-format` here?
> > 
> > To be clear, I'm not proposing that the source code you change isn't 
> > syntactically formatted. But `git format-patch` does not do syntactic 
> > formatting, it just writes a diff to disk.
> > 
> > I don't think it matters how you generate your diff, but your changes need 
> > to have gone through `git clang-format` as described elsewhere in the llvm 
> > docs.
> Oh, yes, that is confusion on my end! I was thinking `git clang-format`, so 
> this part is fine by me. Thanks!
Woah! I just realized that `-U 99` and `-U99` are interpreted 
differently by `git`. We need the latter.


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

https://reviews.llvm.org/D128645

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


[PATCH] D128604: [RISCV] Support Zbpbo extension

2022-06-28 Thread Shao-Ce SUN via Phabricator via cfe-commits
sunshaoce updated this revision to Diff 440613.
sunshaoce added a comment.

Rebased on D128644 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128604

Files:
  clang/include/clang/Basic/BuiltinsRISCV.def
  clang/test/CodeGen/RISCV/rvp-intrinsics/riscv32-zbpbo.c
  clang/test/CodeGen/RISCV/rvp-intrinsics/riscv64-zbpbo.c
  clang/test/Driver/riscv-arch.c
  clang/test/Preprocessor/riscv-target-features.c
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/RISCV.td
  llvm/lib/Target/RISCV/RISCVISelLowering.cpp
  llvm/lib/Target/RISCV/RISCVInstrInfoZb.td
  llvm/lib/Target/RISCV/RISCVSubtarget.h
  llvm/test/CodeGen/RISCV/attributes.ll
  llvm/test/CodeGen/RISCV/rv32zbpbo-intrinsics.ll
  llvm/test/CodeGen/RISCV/rv32zbpbo.ll
  llvm/test/CodeGen/RISCV/rv64zbpbo-intrinsics.ll
  llvm/test/CodeGen/RISCV/rv64zbpbo.ll
  llvm/test/MC/RISCV/attribute-arch.s
  llvm/test/MC/RISCV/rv32zbpbo-aliases-valid.s
  llvm/test/MC/RISCV/rv32zbpbo-valid.s
  llvm/test/MC/RISCV/rv64zbpbo-aliases-valid.s
  llvm/test/MC/RISCV/rv64zbpbo-valid.s

Index: llvm/test/MC/RISCV/rv64zbpbo-valid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rv64zbpbo-valid.s
@@ -0,0 +1,29 @@
+# RUN: llvm-mc %s -triple=riscv64 -mattr=+experimental-zbpbo -riscv-no-aliases -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+experimental-zbpbo < %s \
+# RUN: | llvm-objdump --mattr=+experimental-zbpbo -M no-aliases -d -r - \
+# RUN: | FileCheck --check-prefix=CHECK-ASM-AND-OBJ %s
+
+# CHECK-ASM-AND-OBJ: pack t0, t1, t2
+# CHECK-ASM: encoding: [0xb3,0x42,0x73,0x08]
+pack t0, t1, t2
+
+# CHECK-ASM-AND-OBJ: packu t0, t1, t2
+# CHECK-ASM: encoding: [0xb3,0x42,0x73,0x48]
+packu t0, t1, t2
+
+# CHECK-ASM-AND-OBJ: fsrw t0, t1, t2, t3
+# CHECK-ASM: encoding: [0xbb,0x52,0xc3,0x3d]
+fsrw t0, t1, t2, t3
+
+# CHECK-ASM-AND-OBJ: max t0, t1, t2
+# CHECK-ASM: encoding: [0xb3,0x62,0x73,0x0a]
+max t0, t1, t2
+
+# CHECK-ASM-AND-OBJ: min t0, t1, t2
+# CHECK-ASM: encoding: [0xb3,0x42,0x73,0x0a]
+min t0, t1, t2
+
+# CHECK-ASM-AND-OBJ: cmix t0, t1, t2, t3
+# CHECK-ASM: encoding: [0xb3,0x92,0x63,0xe6]
+cmix t0, t1, t2, t3
Index: llvm/test/MC/RISCV/rv64zbpbo-aliases-valid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rv64zbpbo-aliases-valid.s
@@ -0,0 +1,18 @@
+# RUN: llvm-mc %s -triple=riscv64 -mattr=+experimental-zbpbo -riscv-no-aliases \
+# RUN: | FileCheck -check-prefixes=CHECK-S-OBJ-NOALIAS %s
+# RUN: llvm-mc %s  -triple=riscv64 -mattr=+experimental-zbpbo \
+# RUN: | FileCheck -check-prefixes=CHECK-S-OBJ %s
+# RUN: llvm-mc -filetype=obj -triple riscv64 -mattr=+experimental-zbpbo < %s \
+# RUN: | llvm-objdump -d -r -M no-aliases --mattr=+experimental-zbpbo - \
+# RUN: | FileCheck -check-prefixes=CHECK-S-OBJ-NOALIAS %s
+# RUN: llvm-mc -filetype=obj -triple riscv64 -mattr=+experimental-zbpbo < %s \
+# RUN: | llvm-objdump -d -r --mattr=+experimental-zbpbo - \
+# RUN: | FileCheck -check-prefixes=CHECK-S-OBJ %s
+
+# CHECK-S-OBJ-NOALIAS: grevi t0, t1, 8
+# CHECK-S-OBJ: rev8.h t0, t1
+rev8.h x5, x6
+
+# CHECK-S-OBJ-NOALIAS: grevi t0, t1, 63
+# CHECK-S-OBJ: rev t0, t1
+rev x5, x6
Index: llvm/test/MC/RISCV/rv32zbpbo-valid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rv32zbpbo-valid.s
@@ -0,0 +1,37 @@
+# RUN: llvm-mc %s -triple=riscv32 -mattr=+experimental-zbpbo -riscv-no-aliases -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s
+# RUN: llvm-mc -filetype=obj -triple=riscv32 -mattr=+experimental-zbpbo < %s \
+# RUN: | llvm-objdump --mattr=+experimental-zbpbo -M no-aliases -d -r - \
+# RUN: | FileCheck --check-prefix=CHECK-ASM-AND-OBJ %s
+
+# CHECK-ASM-AND-OBJ: clz t0, t1
+# CHECK-ASM: encoding: [0x93,0x12,0x03,0x60]
+clz t0, t1
+
+# CHECK-ASM-AND-OBJ: pack t0, t1, t2
+# CHECK-ASM: encoding: [0xb3,0x42,0x73,0x08]
+pack t0, t1, t2
+
+# CHECK-ASM-AND-OBJ: packu t0, t1, t2
+# CHECK-ASM: encoding: [0xb3,0x42,0x73,0x48]
+packu t0, t1, t2
+
+# CHECK-ASM-AND-OBJ: fsr t0, t1, t2, t3
+# CHECK-ASM: encoding: [0xb3,0x52,0xc3,0x3d]
+fsr t0, t1, t2, t3
+
+# CHECK-ASM-AND-OBJ: fsri t0, t1, t2, 0
+# CHECK-ASM: encoding: [0x93,0x52,0x03,0x3c]
+fsri t0, t1, t2, 0
+
+# CHECK-ASM-AND-OBJ: max t0, t1, t2
+# CHECK-ASM: encoding: [0xb3,0x62,0x73,0x0a]
+max t0, t1, t2
+
+# CHECK-ASM-AND-OBJ: min t0, t1, t2
+# CHECK-ASM: encoding: [0xb3,0x42,0x73,0x0a]
+min t0, t1, t2
+
+# CHECK-ASM-AND-OBJ: cmix t0, t1, t2, t3
+# CHECK-ASM: encoding: [0xb3,0x92,0x63,0xe6]
+cmix t0, t1, t2, t3
Index: llvm/test/MC/RISCV/rv32zbpbo-aliases-valid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rv32zbpbo-aliases-valid.s
@

[PATCH] D128649: [clang-cl] Handle some pragma alloc_text corner cases handled by MSVC

2022-06-28 Thread Stephen Long via Phabricator via cfe-commits
steplong updated this revision to Diff 440618.
steplong added a comment.

- Rework logic for rejecting non-functions and non-extern C functions when C++


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128649

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaAttr.cpp
  clang/test/Sema/pragma-ms-alloc-text.c
  clang/test/Sema/pragma-ms-alloc-text.cpp


Index: clang/test/Sema/pragma-ms-alloc-text.cpp
===
--- clang/test/Sema/pragma-ms-alloc-text.cpp
+++ clang/test/Sema/pragma-ms-alloc-text.cpp
@@ -40,3 +40,20 @@
 #pragma alloc_text(c, foo6) // no-warning
 void foo6() {}
 }
+
+extern "C" {
+static void foo7();
+}
+static void foo7();
+#pragma alloc_text(c, foo7) // no-warning
+void foo7() {}
+
+static void foo8();
+extern "C" {
+static void foo8();
+}
+#pragma alloc_text(c, foo8) // expected-error {{'#pragma alloc_text' is 
applicable only to functions with C linkage}}
+void foo8() {}
+
+enum foo9 { A, B, C };
+#pragma alloc_text(c, foo9) // expected-error {{'#pragma alloc_text' is 
applicable only to functions}}
Index: clang/test/Sema/pragma-ms-alloc-text.c
===
--- clang/test/Sema/pragma-ms-alloc-text.c
+++ clang/test/Sema/pragma-ms-alloc-text.c
@@ -1,9 +1,12 @@
 // RUN: %clang_cc1 -fms-extensions -fsyntax-only -verify %s
 
 void foo();
-#pragma alloc_text("hello", foo) // expected-no-diagnostics
+#pragma alloc_text("hello", foo) // no-error
 void foo() {}
 
 static void foo1();
-#pragma alloc_text("hello", foo1) // expected-no-diagnostics
+#pragma alloc_text("hello", foo1) // no-error
 void foo1() {}
+
+int foo2;
+#pragma alloc_text(c, foo2) // expected-error {{'#pragma alloc_text' is 
applicable only to functions}}
Index: clang/lib/Sema/SemaAttr.cpp
===
--- clang/lib/Sema/SemaAttr.cpp
+++ clang/lib/Sema/SemaAttr.cpp
@@ -810,8 +810,13 @@
   return;
 }
 
-DeclContext *DC = ND->getDeclContext();
-if (getLangOpts().CPlusPlus && !DC->isExternCContext()) {
+auto *FD = dyn_cast(ND->getCanonicalDecl());
+if (!FD) {
+  Diag(Loc, diag::err_pragma_alloc_text_not_function);
+  return;
+}
+
+if (getLangOpts().CPlusPlus && !FD->isInExternCContext()) {
   Diag(Loc, diag::err_pragma_alloc_text_c_linkage);
   return;
 }
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -992,6 +992,8 @@
   "'#pragma %0' can only appear at file scope">;
 def err_pragma_alloc_text_c_linkage: Error<
   "'#pragma alloc_text' is applicable only to functions with C linkage">;
+def err_pragma_alloc_text_not_function: Error<
+  "'#pragma alloc_text' is applicable only to functions">;
 
 def warn_pragma_unused_undeclared_var : Warning<
   "undeclared variable %0 used as an argument for '#pragma unused'">,


Index: clang/test/Sema/pragma-ms-alloc-text.cpp
===
--- clang/test/Sema/pragma-ms-alloc-text.cpp
+++ clang/test/Sema/pragma-ms-alloc-text.cpp
@@ -40,3 +40,20 @@
 #pragma alloc_text(c, foo6) // no-warning
 void foo6() {}
 }
+
+extern "C" {
+static void foo7();
+}
+static void foo7();
+#pragma alloc_text(c, foo7) // no-warning
+void foo7() {}
+
+static void foo8();
+extern "C" {
+static void foo8();
+}
+#pragma alloc_text(c, foo8) // expected-error {{'#pragma alloc_text' is applicable only to functions with C linkage}}
+void foo8() {}
+
+enum foo9 { A, B, C };
+#pragma alloc_text(c, foo9) // expected-error {{'#pragma alloc_text' is applicable only to functions}}
Index: clang/test/Sema/pragma-ms-alloc-text.c
===
--- clang/test/Sema/pragma-ms-alloc-text.c
+++ clang/test/Sema/pragma-ms-alloc-text.c
@@ -1,9 +1,12 @@
 // RUN: %clang_cc1 -fms-extensions -fsyntax-only -verify %s
 
 void foo();
-#pragma alloc_text("hello", foo) // expected-no-diagnostics
+#pragma alloc_text("hello", foo) // no-error
 void foo() {}
 
 static void foo1();
-#pragma alloc_text("hello", foo1) // expected-no-diagnostics
+#pragma alloc_text("hello", foo1) // no-error
 void foo1() {}
+
+int foo2;
+#pragma alloc_text(c, foo2) // expected-error {{'#pragma alloc_text' is applicable only to functions}}
Index: clang/lib/Sema/SemaAttr.cpp
===
--- clang/lib/Sema/SemaAttr.cpp
+++ clang/lib/Sema/SemaAttr.cpp
@@ -810,8 +810,13 @@
   return;
 }
 
-DeclContext *DC = ND->getDeclContext();
-if (getLangOpts().CPlusPlus && !DC->isExternCContext()) {
+auto *FD = dyn_cast(ND->getCanonicalDecl());
+if (!FD) {
+  Diag(Loc, diag::err_pragma_alloc_text_not

[PATCH] D128649: [clang-cl] Handle some pragma alloc_text corner cases handled by MSVC

2022-06-28 Thread Hans Wennborg via Phabricator via cfe-commits
hans accepted this revision.
hans added a comment.
This revision is now accepted and ready to land.

lgtm


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128649

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


[clang] 313f9cd - Update statuses and add tests for C89 DRs

2022-06-28 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2022-06-28T10:29:20-04:00
New Revision: 313f9cd81d01a3a63d3cdc94ee13b21117b2b3bd

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

LOG: Update statuses and add tests for C89 DRs

This mostly finishes the DRs for C89, though there are still a few
outliers which remain. It also corrects some of the statuses of DRs
where it's not clear if it was fully resolved by the committee or not.

As a drive-by, it also adds -fsyntax-only to the tests which are
verifying diagnostic results. This was previously missed by accident.

Added: 
clang/test/C/drs/dr157.c
clang/test/C/drs/dr158.c

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

Removed: 




diff  --git a/clang/test/C/drs/dr0xx.c b/clang/test/C/drs/dr0xx.c
index 522f36c7141f3..3502efefa0813 100644
--- a/clang/test/C/drs/dr0xx.c
+++ b/clang/test/C/drs/dr0xx.c
@@ -1,9 +1,9 @@
-/* RUN: %clang_cc1 -std=c89 -verify=expected,c89only -pedantic 
-Wno-declaration-after-statement -Wno-c11-extensions %s
-   RUN: %clang_cc1 -std=c89 -verify=expected,c89only -pedantic 
-Wno-declaration-after-statement -Wno-c11-extensions -fno-signed-char %s
-   RUN: %clang_cc1 -std=c99 -verify=expected,c99untilc2x -pedantic 
-Wno-c11-extensions %s
-   RUN: %clang_cc1 -std=c11 -verify=expected,c99untilc2x -pedantic %s
-   RUN: %clang_cc1 -std=c17 -verify=expected,c99untilc2x -pedantic %s
-   RUN: %clang_cc1 -std=c2x -verify=expected,c2xandup -pedantic %s
+/* RUN: %clang_cc1 -std=c89 -fsyntax-only -verify=expected,c89only -pedantic 
-Wno-declaration-after-statement -Wno-c11-extensions %s
+   RUN: %clang_cc1 -std=c89 -fsyntax-only -verify=expected,c89only -pedantic 
-Wno-declaration-after-statement -Wno-c11-extensions -fno-signed-char %s
+   RUN: %clang_cc1 -std=c99 -fsyntax-only -verify=expected,c99untilc2x 
-pedantic -Wno-c11-extensions %s
+   RUN: %clang_cc1 -std=c11 -fsyntax-only -verify=expected,c99untilc2x 
-pedantic %s
+   RUN: %clang_cc1 -std=c17 -fsyntax-only -verify=expected,c99untilc2x 
-pedantic %s
+   RUN: %clang_cc1 -std=c2x -fsyntax-only -verify=expected,c2xandup -pedantic 
%s
  */
 
 /* The following are DRs which do not require tests to demonstrate

diff  --git a/clang/test/C/drs/dr157.c b/clang/test/C/drs/dr157.c
new file mode 100644
index 0..64feed5402e6d
--- /dev/null
+++ b/clang/test/C/drs/dr157.c
@@ -0,0 +1,45 @@
+/* RUN: %clang_cc1 -std=c89 -fsyntax-only -pedantic -verify %s
+   RUN: %clang_cc1 -std=c99 -fsyntax-only -pedantic -verify %s
+   RUN: %clang_cc1 -std=c11 -fsyntax-only -pedantic -verify %s
+   RUN: %clang_cc1 -std=c17 -fsyntax-only -pedantic -verify %s
+   RUN: %clang_cc1 -std=c2x -fsyntax-only -pedantic -verify %s
+ */
+
+/* WG14 DR157: yes
+ * Legitimacy of type synonyms
+ *
+ * Part 1 is about whether you can use a typedef to void in place of void in
+ * a function parameter list and still get a function with a prototype that
+ * accepts no arguments. You can.
+ *
+ * Part 2 is about whether you can use a typedef to int in place of int in
+ * the declaration of main(). You can.
+ *
+ * Part 3 is about whether there are situations where a typedef cannot be used
+ * in place of a type name.
+ */
+typedef void dr157_1_t;
+extern int dr157(dr157_1_t); /* ok */
+int dr157(dr157_1_t) { /* ok */
+  /* You cannot combine a typedef with another type specifier. */
+  typedef int Int; /* expected-note {{previous definition is here}} */
+  long Int val;/* expected-error {{redefinition of 'Int' as 
diff erent kind of symbol}}
+  expected-error {{expected ';' at end of declaration}}
+   */
+
+  return 0;
+}
+
+typedef int dr157_2_t;
+dr157_2_t main(void) { /* Still a valid declaration of main() */
+}
+
+/* A function definition cannot use a typedef for the type. */
+typedef void dr157_3_t(void);
+extern dr157_3_t dr157_2 { /* expected-error {{expected ';' after top level 
declarator}} */
+}
+
+/* FIXME: all diagnostics that happen after the previous one about expecting a
+ * a ';' are silenced, so this test needs to be in its own file to prevent
+ * accidentally incorrect testing.
+ */

diff  --git a/clang/test/C/drs/dr158.c b/clang/test/C/drs/dr158.c
new file mode 100644
index 0..45778bda88393
--- /dev/null
+++ b/clang/test/C/drs/dr158.c
@@ -0,0 +1,22 @@
+/* RUN: %clang_cc1 -std=c89 -pedantic -Wno-c11-extensions -verify -emit-llvm 
-o -  %s | FileCheck %s
+   RUN: %clang_cc1 -std=c99 -pedantic -Wno-c11-extensions -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

[PATCH] D128706: [Clang] Disable clang-format entirely for clang/test tree.

2022-06-28 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

The changes here LGTM and I think this is the correct way to go. However, since 
you discovered that it was perhaps intentional that we did some style checking 
on tests, do you think we should have a brief community RFC just to make sure 
everyone's on the same page?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128706

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


[clang-tools-extra] 3f028c0 - [pseudo] Grammar::parseBNF returns Grammar not unique_ptr. NFC

2022-06-28 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2022-06-28T16:34:21+02:00
New Revision: 3f028c02ba6a24b7230fd5907a2b7ba076664a8b

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

LOG: [pseudo] Grammar::parseBNF returns Grammar not unique_ptr. NFC

Added: 


Modified: 
clang-tools-extra/pseudo/benchmarks/Benchmark.cpp
clang-tools-extra/pseudo/fuzzer/Fuzzer.cpp
clang-tools-extra/pseudo/gen/Main.cpp
clang-tools-extra/pseudo/include/clang-pseudo/grammar/Grammar.h
clang-tools-extra/pseudo/lib/cxx/CXX.cpp
clang-tools-extra/pseudo/lib/grammar/GrammarBNF.cpp
clang-tools-extra/pseudo/tool/ClangPseudo.cpp
clang-tools-extra/pseudo/unittests/ForestTest.cpp
clang-tools-extra/pseudo/unittests/GLRTest.cpp
clang-tools-extra/pseudo/unittests/GrammarTest.cpp
clang-tools-extra/pseudo/unittests/LRTableTest.cpp

Removed: 




diff  --git a/clang-tools-extra/pseudo/benchmarks/Benchmark.cpp 
b/clang-tools-extra/pseudo/benchmarks/Benchmark.cpp
index 6002bada2aa21..a06fde7d7149c 100644
--- a/clang-tools-extra/pseudo/benchmarks/Benchmark.cpp
+++ b/clang-tools-extra/pseudo/benchmarks/Benchmark.cpp
@@ -67,7 +67,7 @@ void setupGrammarAndSource() {
   GrammarText = new std::string(ReadFile(GrammarFile));
   SourceText = new std::string(ReadFile(Source));
   std::vector Diags;
-  G = Grammar::parseBNF(*GrammarText, Diags).release();
+  G = new Grammar(Grammar::parseBNF(*GrammarText, Diags));
 }
 
 static void parseBNF(benchmark::State &State) {

diff  --git a/clang-tools-extra/pseudo/fuzzer/Fuzzer.cpp 
b/clang-tools-extra/pseudo/fuzzer/Fuzzer.cpp
index 58367837813ff..d56ccd018df0d 100644
--- a/clang-tools-extra/pseudo/fuzzer/Fuzzer.cpp
+++ b/clang-tools-extra/pseudo/fuzzer/Fuzzer.cpp
@@ -24,7 +24,7 @@ namespace {
 
 class Fuzzer {
   clang::LangOptions LangOpts = clang::pseudo::genericLangOpts();
-  std::unique_ptr G;
+  Grammar G;
   LRTable T;
   bool Print;
 
@@ -44,7 +44,7 @@ class Fuzzer {
 llvm::errs() << Diag << "\n";
   std::exit(1);
 }
-T = LRTable::buildSLR(*G);
+T = LRTable::buildSLR(G);
   }
 
   void operator()(llvm::StringRef Code) {
@@ -59,10 +59,10 @@ class Fuzzer {
 clang::pseudo::ForestArena Arena;
 clang::pseudo::GSS GSS;
 auto &Root =
-glrParse(ParseableStream, clang::pseudo::ParseParams{*G, T, Arena, 
GSS},
- *G->findNonterminal("translation-unit"));
+glrParse(ParseableStream, clang::pseudo::ParseParams{G, T, Arena, GSS},
+ *G.findNonterminal("translation-unit"));
 if (Print)
-  llvm::outs() << Root.dumpRecursive(*G);
+  llvm::outs() << Root.dumpRecursive(G);
   }
 };
 

diff  --git a/clang-tools-extra/pseudo/gen/Main.cpp 
b/clang-tools-extra/pseudo/gen/Main.cpp
index 38cb7f48e2b66..5964cc8143f05 100644
--- a/clang-tools-extra/pseudo/gen/Main.cpp
+++ b/clang-tools-extra/pseudo/gen/Main.cpp
@@ -79,9 +79,9 @@ int main(int argc, char *argv[]) {
 
   switch (Emit) {
   case EmitSymbolList:
-for (clang::pseudo::SymbolID ID = 0; ID < G->table().Nonterminals.size();
+for (clang::pseudo::SymbolID ID = 0; ID < G.table().Nonterminals.size();
  ++ID) {
-  std::string Name = G->symbolName(ID).str();
+  std::string Name = G.symbolName(ID).str();
   // translation-unit -> translation_unit
   std::replace(Name.begin(), Name.end(), '-', '_');
   Out.os() << llvm::formatv("NONTERMINAL({0}, {1})\n", Name, ID);

diff  --git a/clang-tools-extra/pseudo/include/clang-pseudo/grammar/Grammar.h 
b/clang-tools-extra/pseudo/include/clang-pseudo/grammar/Grammar.h
index 8137734bd74fb..382da41397f0e 100644
--- a/clang-tools-extra/pseudo/include/clang-pseudo/grammar/Grammar.h
+++ b/clang-tools-extra/pseudo/include/clang-pseudo/grammar/Grammar.h
@@ -138,12 +138,12 @@ struct GrammarTable;
 // It is a building block for constructing a table-based parser.
 class Grammar {
 public:
+  Grammar() = default; // Creates an invalid dummy grammar.
   explicit Grammar(std::unique_ptr);
 
   // Parses grammar from a BNF file.
   // Diagnostics emitted during parsing are stored in Diags.
-  static std::unique_ptr parseBNF(llvm::StringRef BNF,
-   std::vector &Diags);
+  static Grammar parseBNF(llvm::StringRef BNF, std::vector 
&Diags);
 
   // Returns the SymbolID of the symbol '_'.
   SymbolID underscore() const { return Underscore; };

diff  --git a/clang-tools-extra/pseudo/lib/cxx/CXX.cpp 
b/clang-tools-extra/pseudo/lib/cxx/CXX.cpp
index bcf350ce87fc5..88c2e0fe5f2ee 100644
--- a/clang-tools-extra/pseudo/lib/cxx/CXX.cpp
+++ b/clang-tools-extra/pseudo/lib/cxx/CXX.cpp
@@ -19,7 +19,7 @@ static const char *CXXBNF =
 
 const Grammar &getGrammar() {
   static std::vector Diags;
-  static Grammar *G = Grammar::parseBNF(CXXBNF, Diags).release();
+  sta

[PATCH] D128103: Adds AST Matcher for ObjCStringLiteral

2022-06-28 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a reviewer: aaron.ballman.
aaron.ballman added a comment.

We typically don't add AST matchers until we have a need for them to be used 
in-tree (ASTMatchers.h is already really expensive to parse; adding matchers 
for everything possible with AST nodes would be prohibitively expensive). 
However, this is a case that really seems like it doesn't need to wait for an 
in-tree use because of how foundational the matcher is, so I think it's fine to 
add as-is.




Comment at: clang/docs/LibASTMatchersReference.html:2038
 
+MatcherStmt>objcStringLiteralMatcherObjCStringLiteral>...
+Matches objective-C 
string literals.

It looks like this documentation was added manually -- it should actually live 
in the ASTMatchers.h header file, and then you run 
clang/docs/tools/dump_ast_matchers.py to generate this HTML file automatically.



Comment at: clang/include/clang/ASTMatchers/ASTMatchers.h:1518-1519
 
+extern const internal::VariadicDynCastAllOfMatcher
+objcStringLiteral;
+

You should add your documentation comments above this declaration.


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

https://reviews.llvm.org/D128103

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


[PATCH] D128333: [clang][flang] Disable defaulting to `-fpie` for LLVM Flang

2022-06-28 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski added a comment.

In D128333#3613696 , @MaskRay wrote:

> True. If it is difficult to override the -pie default from flang side, I am 
> fine with the code change.

Thanks! The proper/long-term fix will require extending Flang's frontend driver 
so that it supports `-mrelocation-model`, `-fpic` and `-fpic-level` (and 
probably a few more). But I don't want to rush that.

>>> (Why does flang use clang/lib/Driver? For clang developers, it seems that 
>>> `check-clang check-clang-tools` is not sufficient. `check-flang` needs to 
>>> be used as well.)
>>
>> Otherwise, we'd have to re-implement clang/lib/Driver for LLVM Flang. This 
>> design was proposed and discussed here 
>> .
>
> OK, so you did bring this up. I guess I'll have to accept...

With clangDriver 

 being effectively shared between Clang and Flang, it would make a lot of sense 
to lift `clangDriver` out of Clang so that it's an independent sub-project. 
We've proposed that and folks have been mostly in favor. Relevant RFCs:

- RFC: refactoring libclangDriver/libclangFrontend to share with Flang 

- RFC: refactoring clangDriver - diagnostics classes 


Not much is really happening in this area ATM, but I'm hoping that 
https://discourse.llvm.org/t/rfc-improving-clang-s-diagnostics could unblock 
some progress.




Comment at: flang/test/Driver/no-pie.f90:3
+
+!-
+! RUN COMMANDS

MaskRay wrote:
> The `! RUN COMMANDS` and `EXPECTED OUTPUT` comments seem rather redundant. 
> I'd remove them.
This style is quite common in this directory, see e.g. 
https://github.com/llvm/llvm-project/blob/main/flang/test/Driver/emit-asm-aarch64.f90.
 I'm hoping that this makes these tests easier to follow for folks less 
familiar with LIT in general.

If that's OK, I'll leave this here (but I don't expect others to follow similar 
approach, IMO it's a matter of personal preference).



Comment at: flang/test/Driver/no-pie.f90:11
+!
+! CHECK-NOT: fpie
+! CHECK-NOT: fpic

MaskRay wrote:
> This NOT pattern can easily get stale. You need a test that driver `-pie` 
> forwards `-pie` to the linker and by default `-pie` does not pass the the 
> linker.
Good point, will update!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128333

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


[PATCH] D128653: [PowerPC] Fix the check for scalar MASS conversion

2022-06-28 Thread Masoud Ataei via Phabricator via cfe-commits
masoud.ataei updated this revision to Diff 440625.
masoud.ataei added a comment.

Test updated.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128653

Files:
  clang/test/CodeGen/lower-mass-end-to-end.c
  llvm/lib/Target/PowerPC/PPCISelLowering.cpp
  llvm/lib/Target/PowerPC/PPCISelLowering.h

Index: llvm/lib/Target/PowerPC/PPCISelLowering.h
===
--- llvm/lib/Target/PowerPC/PPCISelLowering.h
+++ llvm/lib/Target/PowerPC/PPCISelLowering.h
@@ -1293,6 +1293,7 @@
 SelectionDAG &DAG) const;
 bool isLowringToMASSFiniteSafe(SDValue Op) const;
 bool isLowringToMASSSafe(SDValue Op) const;
+bool isScalarMASSConversionEnabled() const;
 SDValue lowerLibCallBase(const char *LibCallDoubleName,
  const char *LibCallFloatName,
  const char *LibCallDoubleNameFinite,
Index: llvm/lib/Target/PowerPC/PPCISelLowering.cpp
===
--- llvm/lib/Target/PowerPC/PPCISelLowering.cpp
+++ llvm/lib/Target/PowerPC/PPCISelLowering.cpp
@@ -392,8 +392,7 @@
 
   // MASS transformation for LLVM intrinsics with replicating fast-math flag
   // to be consistent to PPCGenScalarMASSEntries pass
-  if (TM.getOptLevel() == CodeGenOpt::Aggressive &&
-  TM.Options.PPCGenScalarMASSEntries) {
+  if (TM.getOptLevel() == CodeGenOpt::Aggressive) {
 setOperationAction(ISD::FSIN , MVT::f64, Custom);
 setOperationAction(ISD::FCOS , MVT::f64, Custom);
 setOperationAction(ISD::FPOW , MVT::f64, Custom);
@@ -17886,13 +17885,17 @@
   return Op.getNode()->getFlags().hasApproximateFuncs();
 }
 
+bool PPCTargetLowering::isScalarMASSConversionEnabled() const {
+  return getTargetMachine().Options.PPCGenScalarMASSEntries;
+}
+
 SDValue PPCTargetLowering::lowerLibCallBase(const char *LibCallDoubleName,
 const char *LibCallFloatName,
 const char *LibCallDoubleNameFinite,
 const char *LibCallFloatNameFinite,
 SDValue Op,
 SelectionDAG &DAG) const {
-  if (!isLowringToMASSSafe(Op))
+  if (!isScalarMASSConversionEnabled() || !isLowringToMASSSafe(Op))
 return SDValue();
 
   if (!isLowringToMASSFiniteSafe(Op))
Index: clang/test/CodeGen/lower-mass-end-to-end.c
===
--- /dev/null
+++ clang/test/CodeGen/lower-mass-end-to-end.c
@@ -0,0 +1,147 @@
+// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass -O3 -fapprox-func --target=powerpc64le-unknown-linux-gnu -S %s -o -| FileCheck %s -check-prefix=CHECK-MASS-AFN
+// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass -Ofast --target=powerpc64le-unknown-linux-gnu -S %s -o -| FileCheck %s -check-prefix=CHECK-MASS-FAST
+// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass -O3 -fapprox-func --target=powerpc-ibm-aix-xcoff -S %s -o -| FileCheck %s -check-prefix=CHECK-MASS-AFN
+// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass -Ofast --target=powerpc-ibm-aix-xcoff -S %s -o -| FileCheck %s -check-prefix=CHECK-MASS-FAST
+
+// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass=false -O3 -fapprox-func --target=powerpc64le-unknown-linux-gnu -S %s -o -| FileCheck %s -check-prefix=CHECK-NO-MASS-AFN
+// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass=false -Ofast --target=powerpc64le-unknown-linux-gnu -S %s -o -| FileCheck %s -check-prefix=CHECK-NO-MASS-FAST
+// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass=false -O3 -fapprox-func --target=powerpc-ibm-aix-xcoff -S %s -o -| FileCheck %s -check-prefix=CHECK-NO-MASS-AFN
+// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass=false -Ofast --target=powerpc-ibm-aix-xcoff -S %s -o -| FileCheck %s -check-prefix=CHECK-NO-MASS-FAST
+
+// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass -O3 -fno-approx-func --target=powerpc64le-unknown-linux-gnu -S %s -o -| FileCheck %s -check-prefix=CHECK-NO-MASS-AFN
+// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass -fno-fast-math --target=powerpc64le-unknown-linux-gnu -S %s -o -| FileCheck %s -check-prefix=CHECK-NO-MASS-FAST
+// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass -O3 -fno-approx-func --target=powerpc-ibm-aix-xcoff -S %s -o -| FileCheck %s -check-prefix=CHECK-NO-MASS-AFN
+// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass -fno-fast-math --target=powerpc-ibm-aix-xcoff -S %s -o -| FileCheck %s -check-prefix=CHECK-NO-MASS-FAST
+
+extern double sin(double a);
+extern double cos(double a);
+extern double pow(double a, double b);
+extern double log(double a);
+extern double log10(double a);
+extern double exp(double a);
+extern float sinf(float a);
+extern float cosf(float a);
+extern float powf(float a, float b);
+extern float logf(float a);
+extern float log10f(float a);
+extern fl

[PATCH] D128333: [clang][flang] Disable defaulting to `-fpie` for LLVM Flang

2022-06-28 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski updated this revision to Diff 440628.
awarzynski added a comment.

Update the test following the comments from @MaskRay

Also added a comment in Linux.cpp and renamed no-pie.f90 as pic-flags.f90 (to 
avoid FileCheck matching e.g. `! CHECK: pie` against the file name).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128333

Files:
  clang/lib/Driver/ToolChains/Linux.cpp
  flang/test/Driver/pic-flags.f90


Index: flang/test/Driver/pic-flags.f90
===
--- /dev/null
+++ flang/test/Driver/pic-flags.f90
@@ -0,0 +1,24 @@
+! Verify that in contrast to Clang, Flang does not default to generating 
position independent executables/code
+
+!-
+! RUN COMMANDS
+!-
+! RUN: %flang -### %s -target aarch64-linux-gnu 2>&1 | FileCheck %s 
--check-prefix=CHECK-NOPIE
+! RUN: %flang -### %s -target aarch64-linux-gnu -fno-pie 2>&1 | FileCheck %s 
--check-prefix=CHECK-NOPIE
+
+! RUN: %flang -### %s -target aarch64-linux-gnu -fpie 2>&1 | FileCheck %s 
--check-prefix=CHECK-PIE
+
+!
+! EXPECTED OUTPUT
+!
+! CHECK-NOPIE: "-fc1"
+! CHECk-NOPIE-NOT: fpic
+! CHECK-NOPIE: "{{.*}}ld"
+! CHECK-NOPIE-NOT: "-pie"
+
+! CHECK-PIE: "-fc1"
+! TODO: Once Flang supports `-fpie`, it //should// use -fpic when invoking 
`flang -fc1`. Update the following line once `-fpie` is
+! available.
+! CHECk-PIE-NOT: fpic
+! CHECK-PIE: "{{.*}}ld"
+! CHECK-PIE-NOT: "-pie"
Index: clang/lib/Driver/ToolChains/Linux.cpp
===
--- clang/lib/Driver/ToolChains/Linux.cpp
+++ clang/lib/Driver/ToolChains/Linux.cpp
@@ -699,8 +699,11 @@
 }
 
 bool Linux::isPIEDefault(const llvm::opt::ArgList &Args) const {
-  return CLANG_DEFAULT_PIE_ON_LINUX || getTriple().isAndroid() ||
- getTriple().isMusl() || getSanitizerArgs(Args).requiresPIE();
+  // TODO: Remove the special treatment for Flang once its frontend driver can
+  // generate position independent code.
+  return !getDriver().IsFlangMode() &&
+ (CLANG_DEFAULT_PIE_ON_LINUX || getTriple().isAndroid() ||
+  getTriple().isMusl() || getSanitizerArgs(Args).requiresPIE());
 }
 
 bool Linux::IsAArch64OutlineAtomicsDefault(const ArgList &Args) const {


Index: flang/test/Driver/pic-flags.f90
===
--- /dev/null
+++ flang/test/Driver/pic-flags.f90
@@ -0,0 +1,24 @@
+! Verify that in contrast to Clang, Flang does not default to generating position independent executables/code
+
+!-
+! RUN COMMANDS
+!-
+! RUN: %flang -### %s -target aarch64-linux-gnu 2>&1 | FileCheck %s --check-prefix=CHECK-NOPIE
+! RUN: %flang -### %s -target aarch64-linux-gnu -fno-pie 2>&1 | FileCheck %s --check-prefix=CHECK-NOPIE
+
+! RUN: %flang -### %s -target aarch64-linux-gnu -fpie 2>&1 | FileCheck %s --check-prefix=CHECK-PIE
+
+!
+! EXPECTED OUTPUT
+!
+! CHECK-NOPIE: "-fc1"
+! CHECk-NOPIE-NOT: fpic
+! CHECK-NOPIE: "{{.*}}ld"
+! CHECK-NOPIE-NOT: "-pie"
+
+! CHECK-PIE: "-fc1"
+! TODO: Once Flang supports `-fpie`, it //should// use -fpic when invoking `flang -fc1`. Update the following line once `-fpie` is
+! available.
+! CHECk-PIE-NOT: fpic
+! CHECK-PIE: "{{.*}}ld"
+! CHECK-PIE-NOT: "-pie"
Index: clang/lib/Driver/ToolChains/Linux.cpp
===
--- clang/lib/Driver/ToolChains/Linux.cpp
+++ clang/lib/Driver/ToolChains/Linux.cpp
@@ -699,8 +699,11 @@
 }
 
 bool Linux::isPIEDefault(const llvm::opt::ArgList &Args) const {
-  return CLANG_DEFAULT_PIE_ON_LINUX || getTriple().isAndroid() ||
- getTriple().isMusl() || getSanitizerArgs(Args).requiresPIE();
+  // TODO: Remove the special treatment for Flang once its frontend driver can
+  // generate position independent code.
+  return !getDriver().IsFlangMode() &&
+ (CLANG_DEFAULT_PIE_ON_LINUX || getTriple().isAndroid() ||
+  getTriple().isMusl() || getSanitizerArgs(Args).requiresPIE());
 }
 
 bool Linux::IsAArch64OutlineAtomicsDefault(const ArgList &Args) const {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D128645: Update developer policy.

2022-06-28 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: llvm/docs/DeveloperPolicy.rst:87
 
-#. Patches should be made with ``git format-patch``, or similar (see special
-   commands for `Requesting Phabricator review via the web interface
-   `_ ). If you use a
-   different tool, make sure it uses the ``diff -u`` format and that it
-   doesn't contain clutter which makes it hard to read.
-
-Once your patch is ready, submit it by emailing it to the appropriate project's
-commit mailing list (or commit it directly if applicable). Alternatively, some
-patches get sent to the project's development list or component of the LLVM bug
-tracker, but the commit list is the primary place for reviews and should
-generally be preferred.
-
-When sending a patch to a mailing list, it is a good idea to send it as an
-*attachment* to the message, not embedded into the text of the message.  This
-ensures that your mailer will not mangle the patch when it sends it (e.g. by
-making whitespace changes or by wrapping lines).
-
-*For Thunderbird users:* Before submitting a patch, please open *Preferences >
-Advanced > General > Config Editor*, find the key
-``mail.content_disposition_type``, and set its value to ``1``. Without this
-setting, Thunderbird sends your attachment using ``Content-Disposition: 
inline``
-rather than ``Content-Disposition: attachment``. Apple Mail gamely displays 
such
-a file inline, making it difficult to work with for reviewers using that
-program.
-
-When submitting patches, please do not add confidentiality or non-disclosure
-notices to the patches themselves.  These notices conflict with the LLVM
-licensing terms and may result in your contribution being excluded.
+#. Patches should be unified diffs with "infinte context" (i.e. using something
+   like `git diff -U 99 main`).

vext01 wrote:
> aaron.ballman wrote:
> > vext01 wrote:
> > > aaron.ballman wrote:
> > > > Changing this would require an RFC to see if the community wants to get 
> > > > rid of our requirement that patches be formatted. Personally, I'd be 
> > > > opposed to such a change; I think this should be kept.
> > > Is there confusion between `git format-patch` and `git clang-format` here?
> > > 
> > > To be clear, I'm not proposing that the source code you change isn't 
> > > syntactically formatted. But `git format-patch` does not do syntactic 
> > > formatting, it just writes a diff to disk.
> > > 
> > > I don't think it matters how you generate your diff, but your changes 
> > > need to have gone through `git clang-format` as described elsewhere in 
> > > the llvm docs.
> > Oh, yes, that is confusion on my end! I was thinking `git clang-format`, so 
> > this part is fine by me. Thanks!
> Woah! I just realized that `-U 99` and `-U99` are interpreted 
> differently by `git`. We need the latter.
TIL I've been doing it right almost entirely by chance. :-)

You should probably fix up the patch summary as well.



Comment at: llvm/docs/DeveloperPolicy.rst:419-421
-Your first commit to a repository may require the autogenerated email to be
-approved by a moderator of the mailing list.
-This is normal and will be done when the mailing list owner has time.

vext01 wrote:
> aaron.ballman wrote:
> > vext01 wrote:
> > > aaron.ballman wrote:
> > > > Rather than get rid of this, I think we might actually want to broaden 
> > > > it. I read this blurb as letting folks know that sometimes commit 
> > > > messages take a while before they show up on the commit list. It used 
> > > > to be the primary way that happened was when making a commit for the 
> > > > first time. Now it happens most often for large commits (due to the 
> > > > size of the email content) or a long list of CCs (often added 
> > > > automatically by Herald, though the moderation of these has gotten 
> > > > better in recent history).
> > > > 
> > > > I think it's kind of helpful to let people know that sometimes the 
> > > > automated emails get caught out by moderation. But if others don't 
> > > > think that's of value to mention, then we can go ahead and remove this 
> > > > bit.
> > > Actually, now I read it again, I realise that I don't understand what 
> > > this sentence means:
> > > 
> > > > Your first commit to a repository may require the autogenerated email 
> > > > to be approved by a moderator of the mailing list.
> > > 
> > > My first commit to a llvm repository was via github, and github doesn't 
> > > discriminate. If you have write-access to the repo, then your push to 
> > > `main` will surely go ahead. There are no automated emails involved as 
> > > far as I know.
> > > 
> > > I suspect this prose is from pre-github, where the process was different?
> > > Actually, now I read it again, I realise that I don't understand what 
> > > this sentence means:
> > 
> > Ah, I think I see where the confusion may be coming in.
> > 
> > We have a post-commit hook that pushes all commits to a com

[PATCH] D127762: [Clang][AArch64] Add ACLE attributes for SME.

2022-06-28 Thread Sander de Smalen via Phabricator via cfe-commits
sdesmalen updated this revision to Diff 440631.
sdesmalen marked 3 inline comments as done.
sdesmalen added a comment.

- Removed attribute handling from SemaDeclAttr.cpp, so that the type attributes 
are only handled in SemaType.cpp
- Made ArmLocallyStreaming a DeclOrTypeAttribute again.
- Added new tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127762

Files:
  clang/include/clang/AST/Type.h
  clang/include/clang/AST/TypeProperties.td
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/Type.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Basic/Targets/AArch64.h
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGen/aarch64-sme-intrinsics/aarch64-sme-attrs.cpp
  clang/test/Misc/pragma-attribute-supported-attributes-list.test
  clang/test/Sema/aarch64-sme-attrs-no-sme.c
  clang/test/Sema/aarch64-sme-func-attrs.c

Index: clang/test/Sema/aarch64-sme-func-attrs.c
===
--- /dev/null
+++ clang/test/Sema/aarch64-sme-func-attrs.c
@@ -0,0 +1,273 @@
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme -fsyntax-only -verify %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme -fsyntax-only -verify=expected-cpp -x c++ %s
+
+// Valid attributes
+
+__attribute__((arm_streaming)) void sme_arm_streaming(void);
+__attribute__((arm_streaming_compatible)) void sme_arm_streaming_compatible(void);
+
+__attribute__((arm_new_za)) void sme_arm_new_za(void);
+__attribute__((arm_shared_za)) void sme_arm_shared_za(void);
+__attribute__((arm_preserves_za)) void sme_arm_preserves_za(void);
+
+__attribute__((arm_streaming, arm_new_za)) void sme_arm_streaming_new_za(void);
+__attribute__((arm_streaming, arm_shared_za)) void sme_arm_streaming_shared_za(void);
+__attribute__((arm_streaming, arm_preserves_za)) void sme_arm_streaming_preserves_za(void);
+
+__attribute__((arm_streaming_compatible, arm_new_za)) void sme_arm_sc_new_za(void);
+__attribute__((arm_streaming_compatible, arm_shared_za)) void sme_arm_sc_shared_za(void);
+__attribute__((arm_streaming_compatible, arm_preserves_za)) void sme_arm_sc_preserves_za(void);
+
+__attribute__((arm_shared_za, arm_preserves_za)) void sme_arm_shared_preserves_za(void);
+
+__attribute__((arm_locally_streaming)) void sme_arm_locally_streaming(void) { }
+__attribute__((arm_locally_streaming, arm_streaming)) void sme_arm_streaming_and_locally_streaming(void) { }
+__attribute__((arm_locally_streaming, arm_streaming_compatible)) void sme_arm_streaming_and_streaming_compatible(void) { }
+
+__attribute__((arm_locally_streaming, arm_new_za)) void sme_arm_ls_new_za(void) { }
+__attribute__((arm_locally_streaming, arm_shared_za)) void sme_arm_ls_shared_za(void) { }
+__attribute__((arm_locally_streaming, arm_preserves_za)) void sme_arm_ls_preserves_za(void) { }
+
+// Valid attributes on function pointers
+
+void __attribute__((arm_streaming)) streaming_ptr(void);
+typedef __attribute__((arm_streaming)) void (*fptrty1) (void);
+fptrty1 call_streaming_func() { return streaming_ptr; }
+
+void __attribute__((arm_streaming_compatible)) streaming_compatible_ptr(void);
+typedef __attribute__((arm_streaming_compatible)) void (*fptrty2) (void);
+fptrty2 call_sc_func() { return streaming_compatible_ptr; }
+
+void __attribute__((arm_new_za)) new_za_ptr(void);
+typedef __attribute__((arm_new_za)) void (*fptrty3) (void);
+fptrty3 call_new_za_func() { return new_za_ptr; }
+
+void __attribute__((arm_shared_za)) shared_za_ptr(void);
+typedef __attribute__((arm_shared_za)) void (*fptrty4) (void);
+fptrty4 call_shared_za_func() { return shared_za_ptr; }
+
+void __attribute__((arm_preserves_za)) preserves_za_ptr(void);
+typedef __attribute__((arm_preserves_za)) void (*fptrty5) (void);
+fptrty5 call_preserve_za_func() { return preserves_za_ptr; }
+
+void __attribute__((arm_shared_za, arm_preserves_za)) shared_preserves_za_ptr(void);
+typedef __attribute__((arm_shared_za, arm_preserves_za)) void (*fptrty6) (void);
+fptrty6 call_shared_preserve_za_func() { return shared_preserves_za_ptr; }
+
+typedef void (*fptrty7) (void);
+fptrty7 cast_ls_func_to_normal() { return sme_arm_locally_streaming; }
+
+// FIXME: Add invalid function pointer assignments such as assigning:
+//   1. A streaming compatible function to a normal function pointer,
+//   2. A locally streaming function to a streaming function pointer,
+// etc.
+
+// Invalid attributes
+
+// expected-cpp-error@+4 {{'arm_streaming_compatible' and 'arm_streaming' attributes are not compatible}}
+// expected-cpp-note@+3 {{conflicting at

[PATCH] D127762: [Clang][AArch64] Add ACLE attributes for SME.

2022-06-28 Thread Sander de Smalen via Phabricator via cfe-commits
sdesmalen added a comment.

Thanks for your patience reviewing this patch @aaron.ballman!




Comment at: clang/include/clang/AST/Type.h:4064
 bool HasTrailingReturn : 1;
+unsigned AArch64SMEAttributes : 8;
 Qualifiers TypeQuals;

aaron.ballman wrote:
> If we're taking up space in the extra bitfields, why do we need to also take 
> up space in the function prototype itself?
This field is added to ExtProtoInfo struct, which is used to populate the 
ExtraBitfields in the `FunctionPrototype`'s AST node.

Sorry if this wasn't clear because the diff had no context. `arc diff` wasn't 
working for me, so manually updated the patch, but then forgot to add full 
context.



Comment at: clang/include/clang/Basic/Attr.td:2333
 
+def ArmStreamingCompatible : TypeAttr, TargetSpecificAttr {
+  let Spellings = [GNU<"arm_streaming_compatible">];

aaron.ballman wrote:
> You are handling these as declaration attributes in SemaDeclAttr.cpp but 
> declaring them to be type attributes here in Attr.td; that's not okay. If 
> these are type attributes, there should not be code for them in 
> SemaDeclAttr.cpp. (This is why I really think the design needs to be 
> rethought; I think they should be type attributes only, but I think you're 
> trying to match what your specification says.)
Okay, I've removed the handling in SemaDeclAttr, so that it is only handled in 
SemaType.cpp.

But it still allows the attribute to be applied to any position in the function 
declaration, i.e.

  __attribute__((arm_streaming)) float foo1(int);
  float __attribute__((arm_streaming)) foo2(int);
  float foo3(int) __attribute__((arm_streaming));

Is that expected?



Comment at: clang/include/clang/Basic/Attr.td:2345
+
+def ArmLocallyStreaming : DeclOrStmtAttr, TargetSpecificAttr 
{
+  let Spellings = [GNU<"arm_locally_streaming">];

aaron.ballman wrote:
> Why is this a *statement* attribute?
You're right that it shouldn't be. I want it to just be a decl attribute and 
don't want it to be either a Type or a Stmt attribute, but that doesn't seem to 
exist.
I find their meaning quite confusing, because both allow me to limit their 
applicability to Functions. What is the right class to derive from here?



Comment at: clang/include/clang/Basic/Attr.td:2322
 
+def ArmStreamingCompatible : DeclOrTypeAttr, TargetSpecificAttr 
{
+  let Spellings = [Clang<"arm_streaming_compatible">];

aaron.ballman wrote:
> sdesmalen wrote:
> > aaron.ballman wrote:
> > > sdesmalen wrote:
> > > > aaron.ballman wrote:
> > > > > `DeclOrTypeAttr` is only intended to be used for attributes which 
> > > > > were historically a declaration attribute but are semantically type 
> > > > > attributes (like calling conventions). It seems to me that each of 
> > > > > these is purely a type attribute and we shouldn't allow them to be 
> > > > > written in the declaration position. WDYT?
> > > > In this case, I believe the attribute is valid on both the type and the 
> > > > declaration, because the SME ACLE explicitly specifies that the 
> > > > attributes can be applied to both declarations and types.
> > > > 
> > > > The 
> > > > [[https://github.com/ARM-software/acle/pull/188/commits/ce878cf6c43fd824ffc634526e5dfec1ddc1839e#diff-516526d4a18101dc85300bc2033d0f86dc46c505b7510a7694baabea851aedfaR8283-R8294|specification]]
> > > >  says:
> > > > ```Some of the attributes described in this section apply to function 
> > > > types.
> > > > Their semantics are as follows:
> > > > 
> > > > *   If the attribute is attached to a function declaration or 
> > > > definition,
> > > > it applies to the type of the function.
> > > > 
> > > > *   If the attribute is attached to a function type, it applies to that 
> > > > type.
> > > > 
> > > > *   If the attribute is attached to a pointer to a function type, it 
> > > > applies
> > > > to that function type.
> > > > 
> > > > *   Otherwise, the attribute is [ill-formed](#ill-formed).```
> > > > In this case, I believe the attribute is valid on both the type and the 
> > > > declaration, because the SME ACLE explicitly specifies that the 
> > > > attributes can be applied to both declarations and types.
> > > 
> > > What are the chances that can change? Because there are problems here:
> > > 
> > > > If the attribute is attached to a function declaration or definition, 
> > > > it applies to the type of the function.
> > > 
> > > This is egregiously opposed to the design of `[[]]` attributes in both C 
> > > and C++. We came up with `DeclOrTypeAttr` for attributes that previously 
> > > existed, but that is different than introducing new attributes. It's par 
> > > for the course for `__attribute__` style attributes, so I don't worry so 
> > > much there.
> > > 
> > > What's the rationale for this confusing of a design? (e.g., is there some 
> > > reason you basically have to do that, like historically ac

[PATCH] D128645: Update developer policy.

2022-06-28 Thread Edd Barrett via Phabricator via cfe-commits
vext01 added inline comments.



Comment at: llvm/docs/DeveloperPolicy.rst:419-421
-Your first commit to a repository may require the autogenerated email to be
-approved by a moderator of the mailing list.
-This is normal and will be done when the mailing list owner has time.

aaron.ballman wrote:
> vext01 wrote:
> > aaron.ballman wrote:
> > > vext01 wrote:
> > > > aaron.ballman wrote:
> > > > > Rather than get rid of this, I think we might actually want to 
> > > > > broaden it. I read this blurb as letting folks know that sometimes 
> > > > > commit messages take a while before they show up on the commit list. 
> > > > > It used to be the primary way that happened was when making a commit 
> > > > > for the first time. Now it happens most often for large commits (due 
> > > > > to the size of the email content) or a long list of CCs (often added 
> > > > > automatically by Herald, though the moderation of these has gotten 
> > > > > better in recent history).
> > > > > 
> > > > > I think it's kind of helpful to let people know that sometimes the 
> > > > > automated emails get caught out by moderation. But if others don't 
> > > > > think that's of value to mention, then we can go ahead and remove 
> > > > > this bit.
> > > > Actually, now I read it again, I realise that I don't understand what 
> > > > this sentence means:
> > > > 
> > > > > Your first commit to a repository may require the autogenerated email 
> > > > > to be approved by a moderator of the mailing list.
> > > > 
> > > > My first commit to a llvm repository was via github, and github doesn't 
> > > > discriminate. If you have write-access to the repo, then your push to 
> > > > `main` will surely go ahead. There are no automated emails involved as 
> > > > far as I know.
> > > > 
> > > > I suspect this prose is from pre-github, where the process was 
> > > > different?
> > > > Actually, now I read it again, I realise that I don't understand what 
> > > > this sentence means:
> > > 
> > > Ah, I think I see where the confusion may be coming in.
> > > 
> > > We have a post-commit hook that pushes all commits to a commits email 
> > > list: https://lists.llvm.org/pipermail/cfe-commits/ (as an example, 
> > > there's also commits list for LLVM and others), and it's existed for a 
> > > *long time*. It used to be that your commits were written to the commits 
> > > list as though they came from you directly (e.g., 
> > > https://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20130225/074838.html),
> > >  and these days they come in as though from a list bot (e.g., 
> > > https://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20220627/424937.html);
> > >  check out the from line just below the title to spot the differences. So 
> > > the old issue was that when you first pushed a commit, you may not have 
> > > been subscribed to cfe-commits and your commit message wouldn't make it 
> > > to the lists. Now the issue is that when you push any commit, it might be 
> > > caught up by moderation filters (this also used to be an issue, but it 
> > > wasn't the most likely issue for people to hit).
> > OK, so what do you recommend we do? This prose is currently full of 
> > historic details that are confusing/intimidating for a newbie.
> > 
> > Does the sentence still apply, or can we kill it? 
> Do you think something along these lines is still intimidating for a newbie?
> 
> "For external tracking purposes, committed changes are automatically 
> reflected on a commits mailing list (link to llvm-commits archive, link to 
> cfe-commits archive) soon after the commit lands. Note, these mailing lists 
> are moderated and it is not unusual for a large commit to require a moderator 
> to approve the email, so do not be concerned if a commit does not immediately 
> appear in the archives."
> 
> Or something along these lines? Basically, I think it's useful for people to 
> know that the commit is automatically reflected somewhere (so your commit 
> messages are more visible than just git log/blame) and that's it's not 
> something you need to worry about as a committer if you don't see your commit 
> immediately because all the emails get reflected eventually.
That makes a lot more sense to me. I'll make that change and supply a revised 
diff. Thanks.


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

https://reviews.llvm.org/D128645

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


[PATCH] D128645: Update developer policy.

2022-06-28 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 added inline comments.



Comment at: llvm/docs/DeveloperPolicy.rst:87
 
-#. Patches should be made with ``git format-patch``, or similar (see special
-   commands for `Requesting Phabricator review via the web interface
-   `_ ). If you use a
-   different tool, make sure it uses the ``diff -u`` format and that it
-   doesn't contain clutter which makes it hard to read.
-
-Once your patch is ready, submit it by emailing it to the appropriate project's
-commit mailing list (or commit it directly if applicable). Alternatively, some
-patches get sent to the project's development list or component of the LLVM bug
-tracker, but the commit list is the primary place for reviews and should
-generally be preferred.
-
-When sending a patch to a mailing list, it is a good idea to send it as an
-*attachment* to the message, not embedded into the text of the message.  This
-ensures that your mailer will not mangle the patch when it sends it (e.g. by
-making whitespace changes or by wrapping lines).
-
-*For Thunderbird users:* Before submitting a patch, please open *Preferences >
-Advanced > General > Config Editor*, find the key
-``mail.content_disposition_type``, and set its value to ``1``. Without this
-setting, Thunderbird sends your attachment using ``Content-Disposition: 
inline``
-rather than ``Content-Disposition: attachment``. Apple Mail gamely displays 
such
-a file inline, making it difficult to work with for reviewers using that
-program.
-
-When submitting patches, please do not add confidentiality or non-disclosure
-notices to the patches themselves.  These notices conflict with the LLVM
-licensing terms and may result in your contribution being excluded.
+#. Patches should be unified diffs with "infinte context" (i.e. using something
+   like `git diff -U 99 main`).

aaron.ballman wrote:
> vext01 wrote:
> > aaron.ballman wrote:
> > > vext01 wrote:
> > > > aaron.ballman wrote:
> > > > > Changing this would require an RFC to see if the community wants to 
> > > > > get rid of our requirement that patches be formatted. Personally, I'd 
> > > > > be opposed to such a change; I think this should be kept.
> > > > Is there confusion between `git format-patch` and `git clang-format` 
> > > > here?
> > > > 
> > > > To be clear, I'm not proposing that the source code you change isn't 
> > > > syntactically formatted. But `git format-patch` does not do syntactic 
> > > > formatting, it just writes a diff to disk.
> > > > 
> > > > I don't think it matters how you generate your diff, but your changes 
> > > > need to have gone through `git clang-format` as described elsewhere in 
> > > > the llvm docs.
> > > Oh, yes, that is confusion on my end! I was thinking `git clang-format`, 
> > > so this part is fine by me. Thanks!
> > Woah! I just realized that `-U 99` and `-U99` are interpreted 
> > differently by `git`. We need the latter.
> TIL I've been doing it right almost entirely by chance. :-)
> 
> You should probably fix up the patch summary as well.
typo "infinte"



Comment at: llvm/docs/DeveloperPolicy.rst:88
+#. Patches should be unified diffs with "infinte context" (i.e. using something
+   like `git diff -U 99 main`).
+

main is weird example here imho.


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

https://reviews.llvm.org/D128645

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


[PATCH] D108469: Improve handling of static assert messages.

2022-06-28 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Patch application is still failing the precommit CI; it'd be nice to get that 
corrected for some early test feedback.




Comment at: clang/docs/ReleaseNotes.rst:275
   This fixes `Issue 55962 
`_.
+- Printable Unicode characters within `static_assert` messages are no longer
+  escaped.





Comment at: clang/lib/Sema/SemaDeclCXX.cpp:16592
+StringLiteral *MsgStr = cast(AssertMessage);
+if (MsgStr->getCharByteWidth() == 1)
+  Msg << MsgStr->getString();

cor3ntin wrote:
> cor3ntin wrote:
> > aaron.ballman wrote:
> > > Do we want to use something like `isASCII()` here instead of just 
> > > checking for a single-byte width? e.g., pascal strings are single byte 
> > > width, but probably not something we want printed this way.
> > > 
> > > Another question is, do we want to do something slightly slower (since we 
> > > know we're already on the failure path, the performance here shouldn't 
> > > matter overly much) by checking `!containsNonAsciiOrNull()`?
> > > Do we want to use something like isASCII() here instead of just checking 
> > > for a single-byte width? e.g., pascal strings are single byte width, but 
> > > probably not something we want printed this way.
> > 
> > Maybe yes. I though about supporting `u8`, but we should definitively not 
> > make effort for string with a prefix
> > 
> > > Another question is, do we want to do something slightly slower (since we 
> > > know we're already on the failure path, the performance here shouldn't 
> > > matter overly much) by checking !containsNonAsciiOrNull()
> > 
> > No, we want to render unicode characters properly.
> Done.
> with this change
> 
> 
> ```
> static_assert(false, "Ω");  // outputs Ω 
> static_assert(false, u8"Ω");  // ouputs u8"\316\251"
> ```
> 
> I think this makes sense. Or rather using `u8` in static)assert makes no 
> sense so it's not an issue, even a good thing not to have any special 
> handling. disuade people from using prefixes in that context.
>>Another question is, do we want to do something slightly slower (since we 
>>know we're already on the failure path, the performance here shouldn't matter 
>>overly much) by checking !containsNonAsciiOrNull()
> No, we want to render unicode characters properly.

Ah derp, good point.

Thanks for the switch to `isASCII()` -- I agree that we shouldn't go to great 
lengths to support prefixes there until WG21 decides what to do with 
compile-time strings.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108469

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


[PATCH] D128645: Update developer policy.

2022-06-28 Thread Edd Barrett via Phabricator via cfe-commits
vext01 added inline comments.



Comment at: llvm/docs/DeveloperPolicy.rst:88
+#. Patches should be unified diffs with "infinte context" (i.e. using something
+   like `git diff -U 99 main`).
+

xbolva00 wrote:
> main is weird example here imho.
How comes? The docs told me to make my diffs off `main`, so that's what you'd 
be diffing against typically. No?


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

https://reviews.llvm.org/D128645

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


[PATCH] D128319: Survive #pragma once from virtual file.

2022-06-28 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev added a comment.

Historically, the patch was developed before the extended support of virtual 
files in Clang. Given that this is very hard to test and it looks like this is 
not needed on our end anymore. I'd propose to pause this for now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128319

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


[PATCH] D108469: Improve handling of static assert messages.

2022-06-28 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 440640.
cor3ntin added a comment.

Try to fix the patch application issue


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108469

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Basic/Diagnostic.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/StaticAnalyzer/Checkers/PaddingChecker.cpp
  clang/test/C/drs/dr0xx.c
  clang/test/CXX/dcl.dcl/p4-0x.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.id/p3.cpp
  clang/test/Lexer/null-character-in-literal.c
  clang/test/Misc/diag-special-chars.c
  clang/test/Misc/wrong-encoding.c
  clang/test/PCH/cxx-static_assert.cpp
  clang/test/Sema/static-assert.c
  clang/test/SemaCXX/int-ptr-cast-SFINAE.cpp
  clang/test/SemaCXX/static-assert.cpp
  llvm/include/llvm/Support/Unicode.h
  llvm/lib/Support/Unicode.cpp

Index: llvm/lib/Support/Unicode.cpp
===
--- llvm/lib/Support/Unicode.cpp
+++ llvm/lib/Support/Unicode.cpp
@@ -19,197 +19,271 @@
 namespace sys {
 namespace unicode {
 
+/// Unicode code points of the categories L, M, N, P, S and Zs are considered
+/// printable.
+/// In addition, U+00AD SOFT HYPHEN is also considered printable, as
+/// it's actually displayed on most terminals. \return true if the character is
+/// considered printable.
 bool isPrintable(int UCS) {
-  // Sorted list of non-overlapping intervals of code points that are not
-  // supposed to be printable.
-  static const UnicodeCharRange NonPrintableRanges[] = {
-{ 0x, 0x001F }, { 0x007F, 0x009F }, { 0x034F, 0x034F },
-{ 0x0378, 0x0379 }, { 0x037F, 0x0383 }, { 0x038B, 0x038B },
-{ 0x038D, 0x038D }, { 0x03A2, 0x03A2 }, { 0x0528, 0x0530 },
-{ 0x0557, 0x0558 }, { 0x0560, 0x0560 }, { 0x0588, 0x0588 },
-{ 0x058B, 0x058E }, { 0x0590, 0x0590 }, { 0x05C8, 0x05CF },
-{ 0x05EB, 0x05EF }, { 0x05F5, 0x0605 }, { 0x061C, 0x061D },
-{ 0x06DD, 0x06DD }, { 0x070E, 0x070F }, { 0x074B, 0x074C },
-{ 0x07B2, 0x07BF }, { 0x07FB, 0x07FF }, { 0x082E, 0x082F },
-{ 0x083F, 0x083F }, { 0x085C, 0x085D }, { 0x085F, 0x089F },
-{ 0x08A1, 0x08A1 }, { 0x08AD, 0x08E3 }, { 0x08FF, 0x08FF },
-{ 0x0978, 0x0978 }, { 0x0980, 0x0980 }, { 0x0984, 0x0984 },
-{ 0x098D, 0x098E }, { 0x0991, 0x0992 }, { 0x09A9, 0x09A9 },
-{ 0x09B1, 0x09B1 }, { 0x09B3, 0x09B5 }, { 0x09BA, 0x09BB },
-{ 0x09C5, 0x09C6 }, { 0x09C9, 0x09CA }, { 0x09CF, 0x09D6 },
-{ 0x09D8, 0x09DB }, { 0x09DE, 0x09DE }, { 0x09E4, 0x09E5 },
-{ 0x09FC, 0x0A00 }, { 0x0A04, 0x0A04 }, { 0x0A0B, 0x0A0E },
-{ 0x0A11, 0x0A12 }, { 0x0A29, 0x0A29 }, { 0x0A31, 0x0A31 },
-{ 0x0A34, 0x0A34 }, { 0x0A37, 0x0A37 }, { 0x0A3A, 0x0A3B },
-{ 0x0A3D, 0x0A3D }, { 0x0A43, 0x0A46 }, { 0x0A49, 0x0A4A },
-{ 0x0A4E, 0x0A50 }, { 0x0A52, 0x0A58 }, { 0x0A5D, 0x0A5D },
-{ 0x0A5F, 0x0A65 }, { 0x0A76, 0x0A80 }, { 0x0A84, 0x0A84 },
-{ 0x0A8E, 0x0A8E }, { 0x0A92, 0x0A92 }, { 0x0AA9, 0x0AA9 },
-{ 0x0AB1, 0x0AB1 }, { 0x0AB4, 0x0AB4 }, { 0x0ABA, 0x0ABB },
-{ 0x0AC6, 0x0AC6 }, { 0x0ACA, 0x0ACA }, { 0x0ACE, 0x0ACF },
-{ 0x0AD1, 0x0ADF }, { 0x0AE4, 0x0AE5 }, { 0x0AF2, 0x0B00 },
-{ 0x0B04, 0x0B04 }, { 0x0B0D, 0x0B0E }, { 0x0B11, 0x0B12 },
-{ 0x0B29, 0x0B29 }, { 0x0B31, 0x0B31 }, { 0x0B34, 0x0B34 },
-{ 0x0B3A, 0x0B3B }, { 0x0B45, 0x0B46 }, { 0x0B49, 0x0B4A },
-{ 0x0B4E, 0x0B55 }, { 0x0B58, 0x0B5B }, { 0x0B5E, 0x0B5E },
-{ 0x0B64, 0x0B65 }, { 0x0B78, 0x0B81 }, { 0x0B84, 0x0B84 },
-{ 0x0B8B, 0x0B8D }, { 0x0B91, 0x0B91 }, { 0x0B96, 0x0B98 },
-{ 0x0B9B, 0x0B9B }, { 0x0B9D, 0x0B9D }, { 0x0BA0, 0x0BA2 },
-{ 0x0BA5, 0x0BA7 }, { 0x0BAB, 0x0BAD }, { 0x0BBA, 0x0BBD },
-{ 0x0BC3, 0x0BC5 }, { 0x0BC9, 0x0BC9 }, { 0x0BCE, 0x0BCF },
-{ 0x0BD1, 0x0BD6 }, { 0x0BD8, 0x0BE5 }, { 0x0BFB, 0x0C00 },
-{ 0x0C04, 0x0C04 }, { 0x0C0D, 0x0C0D }, { 0x0C11, 0x0C11 },
-{ 0x0C29, 0x0C29 }, { 0x0C34, 0x0C34 }, { 0x0C3A, 0x0C3C },
-{ 0x0C45, 0x0C45 }, { 0x0C49, 0x0C49 }, { 0x0C4E, 0x0C54 },
-{ 0x0C57, 0x0C57 }, { 0x0C5A, 0x0C5F }, { 0x0C64, 0x0C65 },
-{ 0x0C70, 0x0C77 }, { 0x0C80, 0x0C81 }, { 0x0C84, 0x0C84 },
-{ 0x0C8D, 0x0C8D }, { 0x0C91, 0x0C91 }, { 0x0CA9, 0x0CA9 },
-{ 0x0CB4, 0x0CB4 }, { 0x0CBA, 0x0CBB }, { 0x0CC5, 0x0CC5 },
-{ 0x0CC9, 0x0CC9 }, { 0x0CCE, 0x0CD4 }, { 0x0CD7, 0x0CDD },
-{ 0x0CDF, 0x0CDF }, { 0x0CE4, 0x0CE5 }, { 0x0CF0, 0x0CF0 },
-{ 0x0CF3, 0x0D01 }, { 0x0D04, 0x0D04 }, { 0x0D0D, 0x0D0D },
-{ 0x0D11, 0x0D11 }, { 0x0D3B, 0x0D3C }, { 0x0D45, 0x0D45 },
-{ 0x0D49, 0x0D49 }, { 0x0D4F, 0x0D56 }, { 0x0D58, 0x0D5F },
-{ 0x0D64, 0x0D65 }, { 0x0D76, 0x0D78 }, { 0x0D80, 0x0D81 },
-{ 0x0D84, 0x0D84 }, { 0x0D97, 0x0D99 }, { 0x0DB2, 0x0DB2 },
-{ 0x0DBC, 0x0DBC }, { 0x0DBE, 0x0DBF }, { 0x0DC7, 0x0DC9 },
-{ 0x0DCB, 0x0DCE }, { 0x0DD5, 0x0DD5 }, { 0x0DD7, 0x0DD7 },
-{ 0x0DE0, 0x0DF1 }, { 0x0DF5, 0x0E00 }, { 0x0E3B, 0x0E

[PATCH] D108469: Improve handling of static assert messages.

2022-06-28 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

I've removed the parent revision as this review no longer requires it to 
proceed. That should get precommit CI working again.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108469

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


[PATCH] D108469: Improve handling of static assert messages.

2022-06-28 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 440642.
cor3ntin added a comment.

Trigger a CI rerun


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108469

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Basic/Diagnostic.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/StaticAnalyzer/Checkers/PaddingChecker.cpp
  clang/test/C/drs/dr0xx.c
  clang/test/CXX/dcl.dcl/p4-0x.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.id/p3.cpp
  clang/test/Lexer/null-character-in-literal.c
  clang/test/Misc/diag-special-chars.c
  clang/test/Misc/wrong-encoding.c
  clang/test/PCH/cxx-static_assert.cpp
  clang/test/Sema/static-assert.c
  clang/test/SemaCXX/int-ptr-cast-SFINAE.cpp
  clang/test/SemaCXX/static-assert.cpp
  llvm/include/llvm/Support/Unicode.h
  llvm/lib/Support/Unicode.cpp

Index: llvm/lib/Support/Unicode.cpp
===
--- llvm/lib/Support/Unicode.cpp
+++ llvm/lib/Support/Unicode.cpp
@@ -19,197 +19,271 @@
 namespace sys {
 namespace unicode {
 
+/// Unicode code points of the categories L, M, N, P, S and Zs are considered
+/// printable.
+/// In addition, U+00AD SOFT HYPHEN is also considered printable, as
+/// it's actually displayed on most terminals. \return true if the character is
+/// considered printable.
 bool isPrintable(int UCS) {
-  // Sorted list of non-overlapping intervals of code points that are not
-  // supposed to be printable.
-  static const UnicodeCharRange NonPrintableRanges[] = {
-{ 0x, 0x001F }, { 0x007F, 0x009F }, { 0x034F, 0x034F },
-{ 0x0378, 0x0379 }, { 0x037F, 0x0383 }, { 0x038B, 0x038B },
-{ 0x038D, 0x038D }, { 0x03A2, 0x03A2 }, { 0x0528, 0x0530 },
-{ 0x0557, 0x0558 }, { 0x0560, 0x0560 }, { 0x0588, 0x0588 },
-{ 0x058B, 0x058E }, { 0x0590, 0x0590 }, { 0x05C8, 0x05CF },
-{ 0x05EB, 0x05EF }, { 0x05F5, 0x0605 }, { 0x061C, 0x061D },
-{ 0x06DD, 0x06DD }, { 0x070E, 0x070F }, { 0x074B, 0x074C },
-{ 0x07B2, 0x07BF }, { 0x07FB, 0x07FF }, { 0x082E, 0x082F },
-{ 0x083F, 0x083F }, { 0x085C, 0x085D }, { 0x085F, 0x089F },
-{ 0x08A1, 0x08A1 }, { 0x08AD, 0x08E3 }, { 0x08FF, 0x08FF },
-{ 0x0978, 0x0978 }, { 0x0980, 0x0980 }, { 0x0984, 0x0984 },
-{ 0x098D, 0x098E }, { 0x0991, 0x0992 }, { 0x09A9, 0x09A9 },
-{ 0x09B1, 0x09B1 }, { 0x09B3, 0x09B5 }, { 0x09BA, 0x09BB },
-{ 0x09C5, 0x09C6 }, { 0x09C9, 0x09CA }, { 0x09CF, 0x09D6 },
-{ 0x09D8, 0x09DB }, { 0x09DE, 0x09DE }, { 0x09E4, 0x09E5 },
-{ 0x09FC, 0x0A00 }, { 0x0A04, 0x0A04 }, { 0x0A0B, 0x0A0E },
-{ 0x0A11, 0x0A12 }, { 0x0A29, 0x0A29 }, { 0x0A31, 0x0A31 },
-{ 0x0A34, 0x0A34 }, { 0x0A37, 0x0A37 }, { 0x0A3A, 0x0A3B },
-{ 0x0A3D, 0x0A3D }, { 0x0A43, 0x0A46 }, { 0x0A49, 0x0A4A },
-{ 0x0A4E, 0x0A50 }, { 0x0A52, 0x0A58 }, { 0x0A5D, 0x0A5D },
-{ 0x0A5F, 0x0A65 }, { 0x0A76, 0x0A80 }, { 0x0A84, 0x0A84 },
-{ 0x0A8E, 0x0A8E }, { 0x0A92, 0x0A92 }, { 0x0AA9, 0x0AA9 },
-{ 0x0AB1, 0x0AB1 }, { 0x0AB4, 0x0AB4 }, { 0x0ABA, 0x0ABB },
-{ 0x0AC6, 0x0AC6 }, { 0x0ACA, 0x0ACA }, { 0x0ACE, 0x0ACF },
-{ 0x0AD1, 0x0ADF }, { 0x0AE4, 0x0AE5 }, { 0x0AF2, 0x0B00 },
-{ 0x0B04, 0x0B04 }, { 0x0B0D, 0x0B0E }, { 0x0B11, 0x0B12 },
-{ 0x0B29, 0x0B29 }, { 0x0B31, 0x0B31 }, { 0x0B34, 0x0B34 },
-{ 0x0B3A, 0x0B3B }, { 0x0B45, 0x0B46 }, { 0x0B49, 0x0B4A },
-{ 0x0B4E, 0x0B55 }, { 0x0B58, 0x0B5B }, { 0x0B5E, 0x0B5E },
-{ 0x0B64, 0x0B65 }, { 0x0B78, 0x0B81 }, { 0x0B84, 0x0B84 },
-{ 0x0B8B, 0x0B8D }, { 0x0B91, 0x0B91 }, { 0x0B96, 0x0B98 },
-{ 0x0B9B, 0x0B9B }, { 0x0B9D, 0x0B9D }, { 0x0BA0, 0x0BA2 },
-{ 0x0BA5, 0x0BA7 }, { 0x0BAB, 0x0BAD }, { 0x0BBA, 0x0BBD },
-{ 0x0BC3, 0x0BC5 }, { 0x0BC9, 0x0BC9 }, { 0x0BCE, 0x0BCF },
-{ 0x0BD1, 0x0BD6 }, { 0x0BD8, 0x0BE5 }, { 0x0BFB, 0x0C00 },
-{ 0x0C04, 0x0C04 }, { 0x0C0D, 0x0C0D }, { 0x0C11, 0x0C11 },
-{ 0x0C29, 0x0C29 }, { 0x0C34, 0x0C34 }, { 0x0C3A, 0x0C3C },
-{ 0x0C45, 0x0C45 }, { 0x0C49, 0x0C49 }, { 0x0C4E, 0x0C54 },
-{ 0x0C57, 0x0C57 }, { 0x0C5A, 0x0C5F }, { 0x0C64, 0x0C65 },
-{ 0x0C70, 0x0C77 }, { 0x0C80, 0x0C81 }, { 0x0C84, 0x0C84 },
-{ 0x0C8D, 0x0C8D }, { 0x0C91, 0x0C91 }, { 0x0CA9, 0x0CA9 },
-{ 0x0CB4, 0x0CB4 }, { 0x0CBA, 0x0CBB }, { 0x0CC5, 0x0CC5 },
-{ 0x0CC9, 0x0CC9 }, { 0x0CCE, 0x0CD4 }, { 0x0CD7, 0x0CDD },
-{ 0x0CDF, 0x0CDF }, { 0x0CE4, 0x0CE5 }, { 0x0CF0, 0x0CF0 },
-{ 0x0CF3, 0x0D01 }, { 0x0D04, 0x0D04 }, { 0x0D0D, 0x0D0D },
-{ 0x0D11, 0x0D11 }, { 0x0D3B, 0x0D3C }, { 0x0D45, 0x0D45 },
-{ 0x0D49, 0x0D49 }, { 0x0D4F, 0x0D56 }, { 0x0D58, 0x0D5F },
-{ 0x0D64, 0x0D65 }, { 0x0D76, 0x0D78 }, { 0x0D80, 0x0D81 },
-{ 0x0D84, 0x0D84 }, { 0x0D97, 0x0D99 }, { 0x0DB2, 0x0DB2 },
-{ 0x0DBC, 0x0DBC }, { 0x0DBE, 0x0DBF }, { 0x0DC7, 0x0DC9 },
-{ 0x0DCB, 0x0DCE }, { 0x0DD5, 0x0DD5 }, { 0x0DD7, 0x0DD7 },
-{ 0x0DE0, 0x0DF1 }, { 0x0DF5, 0x0E00 }, { 0x0E3B, 0x0E3E },
-{ 0x0E5C,

[PATCH] D128715: [clang-tidy] Fix confusable identifiers interaction with DeclContext

2022-06-28 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM, but I have some additional testing requests which might spawn follow-up 
patches.




Comment at: 
clang-tools-extra/test/clang-tidy/checkers/misc/confusable-identifiers.cpp:43
+  return q0 < q1;
+}

It looks like there's quite a bit of missing test coverage for all the various 
situations in C++. Here are some additional test cases to add:
```
template 
struct S {
  template  // Should warn on this one, right?
  void func2() {}
};

template 
void func(int il) { // Should warn on this one, right?
}

template 
void other() {
  int OO = 0; // Should warn on this one, right?
}
int OO = 0; // But not this one

namespace foo {
  int i1;
}

namespace bar {
  int il;  // Should not warn about this
}

namespace foo {
  int il; // But should warn about this
}

struct Base {
  virtual void O0();

private:
  void II();
};

struct Derived : Base {
  void OO(); // We should warn about this
  void I1(); // But not this
};
```
(I'm sure there are more that I've missed, but you get the idea.) If any of 
these point out other issues, feel free to address them in a follow-up patch if 
you'd prefer.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128715

___
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-06-28 Thread Erich Keane via Phabricator via cfe-commits
erichkeane updated this revision to Diff 440643.
erichkeane added a comment.

All tests pass now, I was able to get the template-template checks working 
correctly, and it passes all the tests I have available.  @ChuanqiXu if you 
could review/run what tests you have, it would be greatly appreciated.


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

https://reviews.llvm.org/D126907

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/Decl.h
  clang/include/clang/AST/DeclBase.h
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Sema/Template.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/Decl.cpp
  clang/lib/AST/DeclBase.cpp
  clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
  clang/lib/Sema/SemaConcept.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/lib/Serialization/ASTWriterDecl.cpp
  clang/test/CXX/temp/temp.constr/temp.constr.constr/non-function-templates.cpp
  
clang/test/CXX/temp/temp.constr/temp.constr.order/class-template-partial-specializations.cpp
  
clang/test/CXX/temp/temp.constr/temp.constr.order/var-template-partial-specializations.cpp
  clang/test/SemaTemplate/concepts-friends.cpp
  clang/test/SemaTemplate/concepts.cpp
  clang/test/SemaTemplate/deferred-concept-inst.cpp
  clang/test/SemaTemplate/instantiate-requires-clause.cpp
  clang/test/SemaTemplate/trailing-return-short-circuit.cpp

Index: clang/test/SemaTemplate/trailing-return-short-circuit.cpp
===
--- /dev/null
+++ clang/test/SemaTemplate/trailing-return-short-circuit.cpp
@@ -0,0 +1,62 @@
+// RUN: %clang_cc1 -std=c++20 -verify %s
+
+template 
+  requires(sizeof(T) > 2) || T::value // #FOO_REQ
+void Foo(T){};// #FOO
+
+template 
+void TrailingReturn(T)   // #TRAILING
+  requires(sizeof(T) > 2) || // #TRAILING_REQ
+  T::value   // #TRAILING_REQ_VAL
+{};
+template 
+struct HasValue {
+  static constexpr bool value = B;
+};
+static_assert(sizeof(HasValue) <= 2);
+
+template 
+struct HasValueLarge {
+  static constexpr bool value = B;
+  int I;
+};
+static_assert(sizeof(HasValueLarge) > 2);
+
+void usage() {
+  // Passes the 1st check, short-circuit so the 2nd ::value is not evaluated.
+  Foo(1.0);
+  TrailingReturn(1.0);
+
+  // Fails the 1st check, but has a ::value, so the check happens correctly.
+  Foo(HasValue{});
+  TrailingReturn(HasValue{});
+
+  // Passes the 1st check, but would have passed the 2nd one.
+  Foo(HasValueLarge{});
+  TrailingReturn(HasValueLarge{});
+
+  // Fails the 1st check, fails 2nd because there is no ::value.
+  Foo(true);
+  // expected-error@-1{{no matching function for call to 'Foo'}}
+  // expected-note@#FOO{{candidate template ignored: constraints not satisfied [with T = bool]}}
+  // expected-note@#FOO_REQ{{because 'sizeof(_Bool) > 2' (1 > 2) evaluated to false}}
+  // expected-note@#FOO_REQ{{because substituted constraint expression is ill-formed: type 'bool' cannot be used prior to '::' because it has no members}}
+
+  TrailingReturn(true);
+  // expected-error@-1{{no matching function for call to 'TrailingReturn'}}
+  // expected-note@#TRAILING{{candidate template ignored: constraints not satisfied [with T = bool]}}
+  // expected-note@#TRAILING_REQ{{because 'sizeof(_Bool) > 2' (1 > 2) evaluated to false}}
+  // expected-note@#TRAILING_REQ_VAL{{because substituted constraint expression is ill-formed: type 'bool' cannot be used prior to '::' because it has no members}}
+
+  // Fails the 1st check, fails 2nd because ::value is false.
+  Foo(HasValue{});
+  // expected-error@-1 {{no matching function for call to 'Foo'}}
+  // expected-note@#FOO{{candidate template ignored: constraints not satisfied [with T = HasValue]}}
+  // expected-note@#FOO_REQ{{because 'sizeof(HasValue) > 2' (1 > 2) evaluated to false}}
+  // expected-note@#FOO_REQ{{and 'HasValue::value' evaluated to false}}
+  TrailingReturn(HasValue{});
+  // expected-error@-1 {{no matching function for call to 'TrailingReturn'}}
+  // expected-note@#TRAILING{{candidate template ignored: constraints not satisfied [with T = HasValue]}}
+  // expected-note@#TRAILING_REQ{{because 'sizeof(HasValue) > 2' (1 > 2) evaluated to false}}
+  // expected-note@#TRAILING_REQ_VAL{{and 'HasValue::value' evaluated to false}}
+}
Index: clang/test/SemaTemplate/instantiate-requires-clause.cpp
===
--- clang/test/SemaTemplate/instantiate-requires-clause.cpp
+++ clang/test/SemaTemplate/instantiate-requires-clause.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -std=c++2a -x c++ %s -verify
+// RUN: %clang_cc1 -std=c++2a -x c++ %s -Wno-unused-value -verify
 
 template  requires ((sizeof(Args) == 1), ...)
 // expected-note@-1 {{because 

[PATCH] D128319: Survive #pragma once from virtual file.

2022-06-28 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D128319#3615779 , @v.g.vassilev 
wrote:

> Historically, the patch was developed before the extended support of virtual 
> files in Clang. Given that this is very hard to test and it looks like this 
> is not needed on our end anymore. I'd propose to pause this for now.

That'd be fine by me -- I'd recommend explicitly abandoning the revision in 
Phabricator if you don't intend to work on it (that gets it off everyone's 
review plate).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128319

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


[PATCH] D123952: [FPEnv] Allow CompoundStmt to keep FP options

2022-06-28 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff updated this revision to Diff 440644.
sepavloff added a comment.

Updated patch according to reviewers' notes

- Rename field of CompoundScopeInfo,
- Treat FE_DYNAMIC like other rounding mode arguments in StmtPrinter,
- Rename and optimize method for calculation of FP option difference.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123952

Files:
  clang/include/clang/AST/JSONNodeDumper.h
  clang/include/clang/AST/Stmt.h
  clang/include/clang/AST/TextNodeDumper.h
  clang/include/clang/Basic/LangOptions.h
  clang/include/clang/Sema/ScopeInfo.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/JSONNodeDumper.cpp
  clang/lib/AST/Stmt.cpp
  clang/lib/AST/StmtPrinter.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/Analysis/BodyFarm.cpp
  clang/lib/Basic/LangOptions.cpp
  clang/lib/CodeGen/CGCoroutine.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/test/AST/ast-dump-fpfeatures.cpp
  clang/test/AST/ast-dump-pragma-json.c
  clang/test/AST/ast-print-fp-pragmas.c

Index: clang/test/AST/ast-print-fp-pragmas.c
===
--- /dev/null
+++ clang/test/AST/ast-print-fp-pragmas.c
@@ -0,0 +1,69 @@
+// RUN: %clang_cc1 -ast-print %s -o - | FileCheck %s
+
+float func_1(float x, float y) {
+#pragma STDC FENV_ACCESS ON
+  if (x != 0) {
+return y;
+  }
+  return x + y;
+}
+
+// CHECK-LABEL: float func_1(float x, float y) {
+// CHECK-NEXT:  #pragma STDC FENV_ACCESS ON
+// CHECK-NEXT:  if (x != 0) {
+// CHECK-NEXT:  return y;
+// CHECK-NEXT:  }
+// CHECK-NEXT:  return x + y;
+// CHECK-NEXT:  }
+
+float func_2(float x, float y) {
+#pragma STDC FENV_ACCESS ON
+  if (x != 0) {
+  #pragma STDC FENV_ACCESS OFF
+return y;
+  }
+  return x + y;
+}
+
+// CHECK-LABEL: float func_2(float x, float y) {
+// CHECK-NEXT:  #pragma STDC FENV_ACCESS ON
+// CHECK-NEXT:  if (x != 0) {
+// CHECK-NEXT:  #pragma STDC FENV_ACCESS OFF
+// CHECK-NEXT:  return y;
+// CHECK-NEXT:  }
+// CHECK-NEXT:  return x + y;
+// CHECK-NEXT:  }
+
+float func_3(float x, float y) {
+#pragma STDC FENV_ROUND FE_DOWNWARD
+  return x + y;
+}
+
+// CHECK-LABEL: float func_3(float x, float y) {
+// CHECK-NEXT:  #pragma STDC FENV_ROUND FE_UPWARD
+// CHECK-NEXT:  return x + y;
+// CHECK-NEXT:  }
+
+float func_4(float x, float y, float z) {
+#pragma STDC FENV_ACCESS ON
+#pragma clang fp exceptions(maytrap)
+#pragma STDC FENV_ROUND FE_UPWARD
+  if (z != 0) {
+  #pragma STDC FENV_ACCESS OFF
+  #pragma STDC FENV_ROUND FE_TOWARDZERO
+return z + x;
+  }
+  return x + y;
+}
+
+// CHECK-LABEL: float func_4(float x, float y, float z) {
+// CHECK-NEXT:  #pragma STDC FENV_ACCESS ON
+// CHECK-NEXT:  #pragma clang fp exceptions(maytrap)
+// CHECK-NEXT:  #pragma STDC FENV_ROUND FE_DOWNWARD
+// CHECK-NEXT:  if (z != 0) {
+// CHECK-NEXT:  #pragma STDC FENV_ACCESS OFF
+// CHECK-NEXT:  #pragma STDC FENV_ROUND FE_TOWARDZERO
+// CHECK-NEXT:  return z + x;
+// CHECK-NEXT:  }
+// CHECK-NEXT:  return x + y;
+// CHECK-NEXT:  }
Index: clang/test/AST/ast-dump-pragma-json.c
===
--- /dev/null
+++ clang/test/AST/ast-dump-pragma-json.c
@@ -0,0 +1,485 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -ast-dump=json %s | FileCheck %s
+
+float func_16(float x, float y) {
+  #pragma STDC FENV_ROUND FE_TOWARDZERO
+  if (x < 0) {
+#pragma STDC FENV_ROUND FE_UPWARD
+return x - y;
+  }
+  return x + y;
+}
+
+// NOTE: CHECK lines have been autogenerated by gen_ast_dump_json_test.py
+// using --filters=CompoundStmt
+
+
+// CHECK-NOT: {{^}}Dumping
+// CHECK:  "kind": "CompoundStmt",
+// CHECK-NEXT:  "range": {
+// CHECK-NEXT:   "begin": {
+// CHECK-NEXT:"offset": 116,
+// CHECK-NEXT:"col": 33,
+// CHECK-NEXT:"tokLen": 1
+// CHECK-NEXT:   },
+// CHECK-NEXT:   "end": {
+// CHECK-NEXT:"offset": 249,
+// CHECK-NEXT:"line": 10,
+// CHECK-NEXT:"col": 1,
+// CHECK-NEXT:"tokLen": 1
+// CHECK-NEXT:   }
+// CHECK-NEXT:  },
+// CHECK-NEXT:  "fpoptions": {
+// CHECK-NEXT:   "ConstRoundingMode": 0
+// CHECK-NEXT:  },
+// CHECK-NEXT:  "inner": [
+// CHECK-NEXT:   {
+// CHECK-NEXT:"id": "0x{{.*}}",
+// CHECK-NEXT:"kind": "IfStmt",
+// CHECK-NEXT:"range": {
+// CHECK-NEXT: "begin": {
+// CHECK-NEXT:  "offset": 160,
+// CHECK-NEXT:  "line": 5,
+// CHECK-NEXT:  "col": 3,
+// CHECK-NEXT:  "tokLen": 2
+// CHECK-NEXT: },
+// CHECK-NEXT: "end": {
+// CHECK-NEXT:  "offset": 231,
+// CHECK-NEXT:  "line": 8,
+// CHECK-NEXT:  "col": 3,
+// CHECK-NEXT:  "tokLen": 1
+// CHECK-NEXT: }
+// CHECK-NEXT:},
+// CHECK-NEXT:"inner": [
+// CHECK-

[PATCH] D108469: Improve handling of static assert messages.

2022-06-28 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 440645.
cor3ntin marked an inline comment as done.
cor3ntin added a comment.

Fix rst syntax


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108469

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Basic/Diagnostic.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/StaticAnalyzer/Checkers/PaddingChecker.cpp
  clang/test/C/drs/dr0xx.c
  clang/test/CXX/dcl.dcl/p4-0x.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.id/p3.cpp
  clang/test/Lexer/null-character-in-literal.c
  clang/test/Misc/diag-special-chars.c
  clang/test/Misc/wrong-encoding.c
  clang/test/PCH/cxx-static_assert.cpp
  clang/test/Sema/static-assert.c
  clang/test/SemaCXX/int-ptr-cast-SFINAE.cpp
  clang/test/SemaCXX/static-assert.cpp
  llvm/include/llvm/Support/Unicode.h
  llvm/lib/Support/Unicode.cpp

Index: llvm/lib/Support/Unicode.cpp
===
--- llvm/lib/Support/Unicode.cpp
+++ llvm/lib/Support/Unicode.cpp
@@ -19,197 +19,271 @@
 namespace sys {
 namespace unicode {
 
+/// Unicode code points of the categories L, M, N, P, S and Zs are considered
+/// printable.
+/// In addition, U+00AD SOFT HYPHEN is also considered printable, as
+/// it's actually displayed on most terminals. \return true if the character is
+/// considered printable.
 bool isPrintable(int UCS) {
-  // Sorted list of non-overlapping intervals of code points that are not
-  // supposed to be printable.
-  static const UnicodeCharRange NonPrintableRanges[] = {
-{ 0x, 0x001F }, { 0x007F, 0x009F }, { 0x034F, 0x034F },
-{ 0x0378, 0x0379 }, { 0x037F, 0x0383 }, { 0x038B, 0x038B },
-{ 0x038D, 0x038D }, { 0x03A2, 0x03A2 }, { 0x0528, 0x0530 },
-{ 0x0557, 0x0558 }, { 0x0560, 0x0560 }, { 0x0588, 0x0588 },
-{ 0x058B, 0x058E }, { 0x0590, 0x0590 }, { 0x05C8, 0x05CF },
-{ 0x05EB, 0x05EF }, { 0x05F5, 0x0605 }, { 0x061C, 0x061D },
-{ 0x06DD, 0x06DD }, { 0x070E, 0x070F }, { 0x074B, 0x074C },
-{ 0x07B2, 0x07BF }, { 0x07FB, 0x07FF }, { 0x082E, 0x082F },
-{ 0x083F, 0x083F }, { 0x085C, 0x085D }, { 0x085F, 0x089F },
-{ 0x08A1, 0x08A1 }, { 0x08AD, 0x08E3 }, { 0x08FF, 0x08FF },
-{ 0x0978, 0x0978 }, { 0x0980, 0x0980 }, { 0x0984, 0x0984 },
-{ 0x098D, 0x098E }, { 0x0991, 0x0992 }, { 0x09A9, 0x09A9 },
-{ 0x09B1, 0x09B1 }, { 0x09B3, 0x09B5 }, { 0x09BA, 0x09BB },
-{ 0x09C5, 0x09C6 }, { 0x09C9, 0x09CA }, { 0x09CF, 0x09D6 },
-{ 0x09D8, 0x09DB }, { 0x09DE, 0x09DE }, { 0x09E4, 0x09E5 },
-{ 0x09FC, 0x0A00 }, { 0x0A04, 0x0A04 }, { 0x0A0B, 0x0A0E },
-{ 0x0A11, 0x0A12 }, { 0x0A29, 0x0A29 }, { 0x0A31, 0x0A31 },
-{ 0x0A34, 0x0A34 }, { 0x0A37, 0x0A37 }, { 0x0A3A, 0x0A3B },
-{ 0x0A3D, 0x0A3D }, { 0x0A43, 0x0A46 }, { 0x0A49, 0x0A4A },
-{ 0x0A4E, 0x0A50 }, { 0x0A52, 0x0A58 }, { 0x0A5D, 0x0A5D },
-{ 0x0A5F, 0x0A65 }, { 0x0A76, 0x0A80 }, { 0x0A84, 0x0A84 },
-{ 0x0A8E, 0x0A8E }, { 0x0A92, 0x0A92 }, { 0x0AA9, 0x0AA9 },
-{ 0x0AB1, 0x0AB1 }, { 0x0AB4, 0x0AB4 }, { 0x0ABA, 0x0ABB },
-{ 0x0AC6, 0x0AC6 }, { 0x0ACA, 0x0ACA }, { 0x0ACE, 0x0ACF },
-{ 0x0AD1, 0x0ADF }, { 0x0AE4, 0x0AE5 }, { 0x0AF2, 0x0B00 },
-{ 0x0B04, 0x0B04 }, { 0x0B0D, 0x0B0E }, { 0x0B11, 0x0B12 },
-{ 0x0B29, 0x0B29 }, { 0x0B31, 0x0B31 }, { 0x0B34, 0x0B34 },
-{ 0x0B3A, 0x0B3B }, { 0x0B45, 0x0B46 }, { 0x0B49, 0x0B4A },
-{ 0x0B4E, 0x0B55 }, { 0x0B58, 0x0B5B }, { 0x0B5E, 0x0B5E },
-{ 0x0B64, 0x0B65 }, { 0x0B78, 0x0B81 }, { 0x0B84, 0x0B84 },
-{ 0x0B8B, 0x0B8D }, { 0x0B91, 0x0B91 }, { 0x0B96, 0x0B98 },
-{ 0x0B9B, 0x0B9B }, { 0x0B9D, 0x0B9D }, { 0x0BA0, 0x0BA2 },
-{ 0x0BA5, 0x0BA7 }, { 0x0BAB, 0x0BAD }, { 0x0BBA, 0x0BBD },
-{ 0x0BC3, 0x0BC5 }, { 0x0BC9, 0x0BC9 }, { 0x0BCE, 0x0BCF },
-{ 0x0BD1, 0x0BD6 }, { 0x0BD8, 0x0BE5 }, { 0x0BFB, 0x0C00 },
-{ 0x0C04, 0x0C04 }, { 0x0C0D, 0x0C0D }, { 0x0C11, 0x0C11 },
-{ 0x0C29, 0x0C29 }, { 0x0C34, 0x0C34 }, { 0x0C3A, 0x0C3C },
-{ 0x0C45, 0x0C45 }, { 0x0C49, 0x0C49 }, { 0x0C4E, 0x0C54 },
-{ 0x0C57, 0x0C57 }, { 0x0C5A, 0x0C5F }, { 0x0C64, 0x0C65 },
-{ 0x0C70, 0x0C77 }, { 0x0C80, 0x0C81 }, { 0x0C84, 0x0C84 },
-{ 0x0C8D, 0x0C8D }, { 0x0C91, 0x0C91 }, { 0x0CA9, 0x0CA9 },
-{ 0x0CB4, 0x0CB4 }, { 0x0CBA, 0x0CBB }, { 0x0CC5, 0x0CC5 },
-{ 0x0CC9, 0x0CC9 }, { 0x0CCE, 0x0CD4 }, { 0x0CD7, 0x0CDD },
-{ 0x0CDF, 0x0CDF }, { 0x0CE4, 0x0CE5 }, { 0x0CF0, 0x0CF0 },
-{ 0x0CF3, 0x0D01 }, { 0x0D04, 0x0D04 }, { 0x0D0D, 0x0D0D },
-{ 0x0D11, 0x0D11 }, { 0x0D3B, 0x0D3C }, { 0x0D45, 0x0D45 },
-{ 0x0D49, 0x0D49 }, { 0x0D4F, 0x0D56 }, { 0x0D58, 0x0D5F },
-{ 0x0D64, 0x0D65 }, { 0x0D76, 0x0D78 }, { 0x0D80, 0x0D81 },
-{ 0x0D84, 0x0D84 }, { 0x0D97, 0x0D99 }, { 0x0DB2, 0x0DB2 },
-{ 0x0DBC, 0x0DBC }, { 0x0DBE, 0x0DBF }, { 0x0DC7, 0x0DC9 },
-{ 0x0DCB, 0x0DCE }, { 0x0DD5, 0x0DD5 }, { 0x0DD7, 0x0DD7 },
-{ 0x0DE0, 0x0DF1 }, { 0x0DF5, 0x0E0

[PATCH] D128486: [pseudo] Add error-recovery framework & brace-based recovery

2022-06-28 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 440646.
sammccall added a comment.

rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128486

Files:
  clang-tools-extra/pseudo/include/clang-pseudo/GLR.h
  clang-tools-extra/pseudo/include/clang-pseudo/grammar/Grammar.h
  clang-tools-extra/pseudo/include/clang-pseudo/grammar/LRGraph.h
  clang-tools-extra/pseudo/include/clang-pseudo/grammar/LRTable.h
  clang-tools-extra/pseudo/lib/GLR.cpp
  clang-tools-extra/pseudo/lib/grammar/Grammar.cpp
  clang-tools-extra/pseudo/lib/grammar/GrammarBNF.cpp
  clang-tools-extra/pseudo/lib/grammar/LRGraph.cpp
  clang-tools-extra/pseudo/lib/grammar/LRTableBuild.cpp
  clang-tools-extra/pseudo/test/cxx/empty-member-spec.cpp
  clang-tools-extra/pseudo/test/cxx/recovery-init-list.cpp
  clang-tools-extra/pseudo/unittests/GLRTest.cpp

Index: clang-tools-extra/pseudo/unittests/GLRTest.cpp
===
--- clang-tools-extra/pseudo/unittests/GLRTest.cpp
+++ clang-tools-extra/pseudo/unittests/GLRTest.cpp
@@ -7,6 +7,7 @@
 //===--===//
 
 #include "clang-pseudo/GLR.h"
+#include "clang-pseudo/Bracket.h"
 #include "clang-pseudo/Token.h"
 #include "clang-pseudo/grammar/Grammar.h"
 #include "clang/Basic/LangOptions.h"
@@ -32,11 +33,13 @@
 using Action = LRTable::Action;
 using testing::AllOf;
 using testing::ElementsAre;
+using testing::IsEmpty;
 using testing::UnorderedElementsAre;
 
 MATCHER_P(state, StateID, "") { return arg->State == StateID; }
 MATCHER_P(parsedSymbol, FNode, "") { return arg->Payload == FNode; }
 MATCHER_P(parsedSymbolID, SID, "") { return arg->Payload->symbol() == SID; }
+MATCHER_P(start, Start, "") { return arg->Payload->startTokenIndex() == Start; }
 
 testing::Matcher
 parents(llvm::ArrayRef Parents) {
@@ -238,9 +241,9 @@
   /*State=*/1, /*ForestNode=*/CVQualifierNode, /*Parents=*/{GSSNode0});
   const auto *GSSNode2 = GSStack.addNode(
   /*State=*/2, /*ForestNode=*/CVQualifierNode, /*Parents=*/{GSSNode0});
-  const auto *GSSNode3 =
-  GSStack.addNode(/*State=*/3, /*ForestNode=*/ClassNameNode,
-  /*Parents=*/{GSSNode1});
+  const auto *GSSNode3 = GSStack.addNode(
+  /*State=*/3, /*ForestNode=*/ClassNameNode,
+  /*Parents=*/{GSSNode1});
   const auto *GSSNode4 =
   GSStack.addNode(/*State=*/4, /*ForestNode=*/EnumNameNode,
   /*Parents=*/{GSSNode2});
@@ -363,6 +366,124 @@
   EXPECT_THAT(Heads, ElementsAre(GSSNode1));
 }
 
+TEST_F(GLRTest, Recover) {
+  // Recovery while parsing "word" inside braces.
+  //  Before:
+  //0--1({)--2(?)
+  //  After recovering a `word` at state 1:
+  //0--3(word)  // 3 is goto(1, word)
+  buildGrammar({"word"}, {});
+  LRTable Table = LRTable::buildForTests(
+  G, {{/*State=*/1, id("word"), Action::goTo(3)}}, /*Reduce=*/{},
+  /*Recovery=*/{{/*State=*/1, RecoveryStrategy::Braces, id("word")}});
+
+  auto *LBrace = &Arena.createTerminal(tok::l_brace, 0);
+  auto *Question1 = &Arena.createTerminal(tok::question, 1);
+  const auto *Root = GSStack.addNode(0, nullptr, {});
+  const auto *OpenedBraces = GSStack.addNode(1, LBrace, {Root});
+  const auto *AfterQuestion1 = GSStack.addNode(2, Question1, {OpenedBraces});
+
+  // Need a token stream with paired braces so the strategy works.
+  clang::LangOptions LOptions;
+  TokenStream Tokens = cook(lex("{ ? ? ? }", LOptions), LOptions);
+  pairBrackets(Tokens);
+  std::vector NewHeads;
+
+  unsigned TokenIndex = 2;
+  glrRecover({AfterQuestion1}, TokenIndex, Tokens, {G, Table, Arena, GSStack},
+ NewHeads);
+  EXPECT_EQ(TokenIndex, 4u) << "should skip ahead to matching brace";
+  EXPECT_THAT(NewHeads, ElementsAre(
+AllOf(state(3), parsedSymbolID(id("word")),
+  parents({OpenedBraces}), start(1u;
+  EXPECT_EQ(NewHeads.front()->Payload->kind(), ForestNode::Opaque);
+
+  // Test recovery failure: omit closing brace so strategy fails
+  TokenStream NoRBrace = cook(lex("{ ? ? ? ?", LOptions), LOptions);
+  pairBrackets(NoRBrace);
+  NewHeads.clear();
+  TokenIndex = 2;
+  glrRecover({AfterQuestion1}, TokenIndex, NoRBrace,
+ {G, Table, Arena, GSStack}, NewHeads);
+  EXPECT_EQ(TokenIndex, 3u) << "should advance by 1 by default";
+  EXPECT_THAT(NewHeads, IsEmpty());
+}
+
+TEST_F(GLRTest, RecoverRightmost) {
+  // In a nested block structure, we recover at the innermost possible block.
+  //  Before:
+  //0--1({)--1({)--1({)
+  //  After recovering a `block` at inside the second braces:
+  //0--1({)--2(body)  // 2 is goto(1, body)
+  buildGrammar({"body"}, {});
+  LRTable Table = LRTable::buildForTests(
+  G, {{/*State=*/1, id("body"), Action::goTo(2)}}, /*Reduce=*/{},
+  /*Recovery=*/{{/*State=*/1, RecoveryStrategy::Braces, id("body")}});
+
+  clang::LangOptions LOptions;
+  /

[PATCH] D128645: Update developer policy.

2022-06-28 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 added inline comments.



Comment at: llvm/docs/DeveloperPolicy.rst:88
+#. Patches should be unified diffs with "infinte context" (i.e. using something
+   like `git diff -U 99 main`).
+

vext01 wrote:
> xbolva00 wrote:
> > main is weird example here imho.
> How comes? The docs told me to make my diffs off `main`, so that's what you'd 
> be diffing against typically. No?
Ah, okay. I usually use it without it.


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

https://reviews.llvm.org/D128645

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


[PATCH] D128645: Update developer policy.

2022-06-28 Thread Edd Barrett via Phabricator via cfe-commits
vext01 updated this revision to Diff 440647.
vext01 added a comment.

I've addressed the comments.

I only linked `llvm-commits` (reusing the already defined rst link) as the 
other lists are referenced elsewhere.

Typo also fixed.

After fixing my `-U 99`, grepping the tree for `` in rst files shows 
that all references to `-U99` are correct.


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

https://reviews.llvm.org/D128645

Files:
  llvm/docs/DeveloperPolicy.rst


Index: llvm/docs/DeveloperPolicy.rst
===
--- llvm/docs/DeveloperPolicy.rst
+++ llvm/docs/DeveloperPolicy.rst
@@ -84,30 +84,12 @@
patches may not apply correctly if the underlying code changes between the
time the patch was created and the time it is applied.
 
-#. Patches should be made with ``git format-patch``, or similar (see special
-   commands for `Requesting Phabricator review via the web interface
-   `_ ). If you use a
-   different tool, make sure it uses the ``diff -u`` format and that it
-   doesn't contain clutter which makes it hard to read.
-
-Once your patch is ready, submit it by emailing it to the appropriate project's
-commit mailing list (or commit it directly if applicable). Alternatively, some
-patches get sent to the project's development list or component of the LLVM bug
-tracker, but the commit list is the primary place for reviews and should
-generally be preferred.
-
-When sending a patch to a mailing list, it is a good idea to send it as an
-*attachment* to the message, not embedded into the text of the message.  This
-ensures that your mailer will not mangle the patch when it sends it (e.g. by
-making whitespace changes or by wrapping lines).
-
-*For Thunderbird users:* Before submitting a patch, please open *Preferences >
-Advanced > General > Config Editor*, find the key
-``mail.content_disposition_type``, and set its value to ``1``. Without this
-setting, Thunderbird sends your attachment using ``Content-Disposition: 
inline``
-rather than ``Content-Disposition: attachment``. Apple Mail gamely displays 
such
-a file inline, making it difficult to work with for reviewers using that
-program.
+#. Patches should be unified diffs with "infinite context" (i.e. using 
something
+   like `git diff -U99 main`).
+
+#. Once you have created your patch, create a
+   `Phabricator review `_ for
+   it (or commit it directly if applicable).
 
 When submitting patches, please do not add confidentiality or non-disclosure
 notices to the patches themselves.  These notices conflict with the LLVM
@@ -416,9 +398,11 @@
 provide the name and email address you would like to use in the Author
 property of the commit.
 
-Your first commit to a repository may require the autogenerated email to be
-approved by a moderator of the mailing list.
-This is normal and will be done when the mailing list owner has time.
+For external tracking purposes, committed changes are automatically reflected
+on a commits mailing list soon after the commit lands (e.g. llvm-commits_).
+Note, these mailing lists are moderated and it is not unusual for a large
+commit to require a moderator to approve the email, so do not be concerned if a
+commit does not immediately appear in the archives.
 
 If you have recently been granted commit access, these policies apply:
 


Index: llvm/docs/DeveloperPolicy.rst
===
--- llvm/docs/DeveloperPolicy.rst
+++ llvm/docs/DeveloperPolicy.rst
@@ -84,30 +84,12 @@
patches may not apply correctly if the underlying code changes between the
time the patch was created and the time it is applied.
 
-#. Patches should be made with ``git format-patch``, or similar (see special
-   commands for `Requesting Phabricator review via the web interface
-   `_ ). If you use a
-   different tool, make sure it uses the ``diff -u`` format and that it
-   doesn't contain clutter which makes it hard to read.
-
-Once your patch is ready, submit it by emailing it to the appropriate project's
-commit mailing list (or commit it directly if applicable). Alternatively, some
-patches get sent to the project's development list or component of the LLVM bug
-tracker, but the commit list is the primary place for reviews and should
-generally be preferred.
-
-When sending a patch to a mailing list, it is a good idea to send it as an
-*attachment* to the message, not embedded into the text of the message.  This
-ensures that your mailer will not mangle the patch when it sends it (e.g. by
-making whitespace changes or by wrapping lines).
-
-*For Thunderbird users:* Before submitting a patch, please open *Preferences >
-Advanced > General > Config Editor*, find the key
-``mail.content_disposition_type``, and set its value to ``1``. Without this
-setting, Thunderbird sends your attachment using ``Content-Disposition: inline``
-rather than ``Content-Disposition: attachment``. Apple Mail game

[PATCH] D128604: [RISCV] Support Zbpbo extension

2022-06-28 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: clang/include/clang/Basic/BuiltinsRISCV.def:21
 TARGET_BUILTIN(__builtin_riscv_orc_b_64, "WiWi", "nc", "zbb,64bit")
-TARGET_BUILTIN(__builtin_riscv_clz_32, "ZiZi", "nc", "zbb")
+TARGET_BUILTIN(__builtin_riscv_clz_32, "ZiZi", "nc", "zbb|experimental-zbpbo")
 TARGET_BUILTIN(__builtin_riscv_clz_64, "WiWi", "nc", "zbb,64bit")

What's preventing __builtin_riscv_clz_32 from being used on rv64 with Zbpbo? I 
think you need to add it to isRISCV32Builtin in SemaChecking.cpp but you'll 
also need to check that Zbb isn't enabled.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128604

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


[PATCH] D128645: Update developer policy.

2022-06-28 Thread Edd Barrett via Phabricator via cfe-commits
vext01 added inline comments.



Comment at: llvm/docs/DeveloperPolicy.rst:88
+#. Patches should be unified diffs with "infinte context" (i.e. using something
+   like `git diff -U 99 main`).
+

xbolva00 wrote:
> vext01 wrote:
> > xbolva00 wrote:
> > > main is weird example here imho.
> > How comes? The docs told me to make my diffs off `main`, so that's what 
> > you'd be diffing against typically. No?
> Ah, okay. I usually use it without it.
That would mean you haven't committed your changes, and `git clang-fomat` wont 
work in that case, so committing is best IMHO.


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

https://reviews.llvm.org/D128645

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


[PATCH] D128700: [AMDGPU][Clang] Skip adding noundef attribute to AMDGPU HIP device functions

2022-06-28 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added inline comments.



Comment at: clang/lib/CodeGen/CGCall.cpp:2309
+  bool EnableNoundefAttrs = CodeGenOpts.EnableNoundefAttrs &&
+!(getLangOpts().HIP && getLangOpts().CUDAIsDevice);
+

Shouldn't be limited to HIP. All languages with convergent operations


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128700

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


[PATCH] D128329: [clangd] Also mark output arguments of operator call expressions

2022-06-28 Thread Christian Kandeler via Phabricator via cfe-commits
ckandeler updated this revision to Diff 440650.
ckandeler marked 2 inline comments as done.
ckandeler added a comment.

Improvements as per review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128329

Files:
  clang-tools-extra/clangd/SemanticHighlighting.cpp
  clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp


Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -738,6 +738,11 @@
   )cpp",
   // Modifier for variables passed as non-const references
   R"cpp(
+struct $Class_decl[[ClassWithOp]] {
+void operator()(int);
+void operator()(int, int &);
+void operator()(int, int, const int &);
+};
 void $Function_decl[[fun]](int, const int,
int*, const int*,
int&, const int&,
@@ -759,6 +764,13 @@
$LocalVariable[[array]], 
$LocalVariable_usedAsMutableReference[[array]], 
$LocalVariable[[array]]
);
+  [](int){}($LocalVariable[[val]]);
+  [](int&){}($LocalVariable_usedAsMutableReference[[val]]);
+  [](const int&){}($LocalVariable[[val]]);
+  $Class[[ClassWithOp]] $LocalVariable_decl[[c]];
+  $LocalVariable[[c]]($LocalVariable[[val]]);
+  $LocalVariable[[c]](0, $LocalVariable_usedAsMutableReference[[val]]);
+  $LocalVariable[[c]](0, 0, $LocalVariable[[val]]);
 }
 struct $Class_decl[[S]] {
   $Class_decl[[S]](int&) {
Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
===
--- clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -537,13 +537,17 @@
 if (isa(E))
   return true;
 
-// FIXME ...here it would make sense though.
-if (isa(E))
-  return true;
+// FIXME: consider highlighting parameters of some other overloaded
+// operators as well
+llvm::ArrayRef Args = {E->getArgs(), E->getNumArgs()};
+if (const auto callOp = dyn_cast(E)) {
+  if (callOp->getOperator() != OO_Call)
+return true;
+  Args = Args.drop_front(); // Drop object parameter
+}
 
 highlightMutableReferenceArguments(
-dyn_cast_or_null(E->getCalleeDecl()),
-{E->getArgs(), E->getNumArgs()});
+dyn_cast_or_null(E->getCalleeDecl()), Args);
 
 return true;
   }


Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -738,6 +738,11 @@
   )cpp",
   // Modifier for variables passed as non-const references
   R"cpp(
+struct $Class_decl[[ClassWithOp]] {
+void operator()(int);
+void operator()(int, int &);
+void operator()(int, int, const int &);
+};
 void $Function_decl[[fun]](int, const int,
int*, const int*,
int&, const int&,
@@ -759,6 +764,13 @@
$LocalVariable[[array]], $LocalVariable_usedAsMutableReference[[array]], 
$LocalVariable[[array]]
);
+  [](int){}($LocalVariable[[val]]);
+  [](int&){}($LocalVariable_usedAsMutableReference[[val]]);
+  [](const int&){}($LocalVariable[[val]]);
+  $Class[[ClassWithOp]] $LocalVariable_decl[[c]];
+  $LocalVariable[[c]]($LocalVariable[[val]]);
+  $LocalVariable[[c]](0, $LocalVariable_usedAsMutableReference[[val]]);
+  $LocalVariable[[c]](0, 0, $LocalVariable[[val]]);
 }
 struct $Class_decl[[S]] {
   $Class_decl[[S]](int&) {
Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
===
--- clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -537,13 +537,17 @@
 if (isa(E))
   return true;
 
-// FIXME ...here it would make sense though.
-if (isa(E))
-  return true;
+// FIXME: consider highlighting parameters of some other overloaded
+// operators as well
+llvm::ArrayRef Args = {E->getArgs(), E->getNumArgs()};
+if (const auto callOp = dyn_cast(E)) {
+  if (callOp->getOperator() != OO_Call)
+return true;
+  Args = Args.drop_front(); // Drop object parameter
+}
 
 highlightMutableRefere

[PATCH] D128182: [NFC] Switch FloatModeKind enum class to use bitmask enums

2022-06-28 Thread Jolanta Jensen via Phabricator via cfe-commits
jolanta.jensen updated this revision to Diff 440653.
jolanta.jensen added a comment.

Correcting computation of RealTypeUsesObjCFPRetMask.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128182

Files:
  clang/include/clang/Basic/TargetInfo.h
  clang/lib/Basic/Targets/X86.h


Index: clang/lib/Basic/Targets/X86.h
===
--- clang/lib/Basic/Targets/X86.h
+++ clang/lib/Basic/Targets/X86.h
@@ -14,6 +14,7 @@
 #define LLVM_CLANG_LIB_BASIC_TARGETS_X86_H
 
 #include "OSTargets.h"
+#include "clang/Basic/BitmaskEnum.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Basic/TargetOptions.h"
 #include "llvm/ADT/Triple.h"
@@ -419,8 +420,8 @@
 
 // Use fpret for all types.
 RealTypeUsesObjCFPRetMask =
-((1 << (int)FloatModeKind::Float) | (1 << (int)FloatModeKind::Double) |
- (1 << (int)FloatModeKind::LongDouble));
+(int)(FloatModeKind::Float | FloatModeKind::Double |
+  FloatModeKind::LongDouble);
 
 // x86-32 has atomics up to 8 bytes
 MaxAtomicPromoteWidth = 64;
@@ -699,7 +700,7 @@
 "64-i64:64-f80:128-n8:16:32:64-S128");
 
 // Use fpret only for long double.
-RealTypeUsesObjCFPRetMask = (1 << (int)FloatModeKind::LongDouble);
+RealTypeUsesObjCFPRetMask = (int)FloatModeKind::LongDouble;
 
 // Use fp2ret for _Complex long double.
 ComplexLongDoubleUsesFP2Ret = true;
Index: clang/include/clang/Basic/TargetInfo.h
===
--- clang/include/clang/Basic/TargetInfo.h
+++ clang/include/clang/Basic/TargetInfo.h
@@ -15,6 +15,7 @@
 #define LLVM_CLANG_BASIC_TARGETINFO_H
 
 #include "clang/Basic/AddressSpaces.h"
+#include "clang/Basic/BitmaskEnum.h"
 #include "clang/Basic/CodeGenOptions.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/LangOptions.h"
@@ -52,14 +53,14 @@
 namespace Builtin { struct Info; }
 
 enum class FloatModeKind {
-  NoFloat = 255,
-  Half = 0,
-  Float,
-  Double,
-  LongDouble,
-  Float128,
-  Ibm128,
-  Last = Ibm128
+  NoFloat = 0,
+  Half = 1 << 0,
+  Float = 1 << 1,
+  Double = 1 << 2,
+  LongDouble = 1 << 3,
+  Float128 = 1 << 4,
+  Ibm128 = 1 << 5,
+  LLVM_MARK_AS_BITMASK_ENUM(Ibm128)
 };
 
 /// Fields controlling how types are laid out in memory; these may need to
@@ -221,7 +222,9 @@
   mutable VersionTuple PlatformMinVersion;
 
   unsigned HasAlignMac68kSupport : 1;
-  unsigned RealTypeUsesObjCFPRetMask : (int)FloatModeKind::Last + 1;
+  unsigned RealTypeUsesObjCFPRetMask
+  : llvm::BitmaskEnumDetail::bitWidth(
+(int)FloatModeKind::LLVM_BITMASK_LARGEST_ENUMERATOR);
   unsigned ComplexLongDoubleUsesFP2Ret : 1;
 
   unsigned HasBuiltinMSVaList : 1;
@@ -890,9 +893,7 @@
   /// Check whether the given real type should use the "fpret" flavor of
   /// Objective-C message passing on this target.
   bool useObjCFPRetForRealType(FloatModeKind T) const {
-assert(T <= FloatModeKind::Last &&
-   "T value is larger than RealTypeUsesObjCFPRetMask can handle");
-return RealTypeUsesObjCFPRetMask & (1 << (int)T);
+return RealTypeUsesObjCFPRetMask & llvm::BitmaskEnumDetail::Underlying(T);
   }
 
   /// Check whether _Complex long double should use the "fp2ret" flavor


Index: clang/lib/Basic/Targets/X86.h
===
--- clang/lib/Basic/Targets/X86.h
+++ clang/lib/Basic/Targets/X86.h
@@ -14,6 +14,7 @@
 #define LLVM_CLANG_LIB_BASIC_TARGETS_X86_H
 
 #include "OSTargets.h"
+#include "clang/Basic/BitmaskEnum.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Basic/TargetOptions.h"
 #include "llvm/ADT/Triple.h"
@@ -419,8 +420,8 @@
 
 // Use fpret for all types.
 RealTypeUsesObjCFPRetMask =
-((1 << (int)FloatModeKind::Float) | (1 << (int)FloatModeKind::Double) |
- (1 << (int)FloatModeKind::LongDouble));
+(int)(FloatModeKind::Float | FloatModeKind::Double |
+  FloatModeKind::LongDouble);
 
 // x86-32 has atomics up to 8 bytes
 MaxAtomicPromoteWidth = 64;
@@ -699,7 +700,7 @@
 "64-i64:64-f80:128-n8:16:32:64-S128");
 
 // Use fpret only for long double.
-RealTypeUsesObjCFPRetMask = (1 << (int)FloatModeKind::LongDouble);
+RealTypeUsesObjCFPRetMask = (int)FloatModeKind::LongDouble;
 
 // Use fp2ret for _Complex long double.
 ComplexLongDoubleUsesFP2Ret = true;
Index: clang/include/clang/Basic/TargetInfo.h
===
--- clang/include/clang/Basic/TargetInfo.h
+++ clang/include/clang/Basic/TargetInfo.h
@@ -15,6 +15,7 @@
 #define LLVM_CLANG_BASIC_TARGETINFO_H
 
 #include "clang/Basic/AddressSpaces.h"
+#include "clang/Basic/BitmaskEnum.h"
 #include "clang/Basic/CodeGenOptions.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/LangOptions.h"
@@

[PATCH] D123952: [FPEnv] Allow CompoundStmt to keep FP options

2022-06-28 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff added inline comments.



Comment at: clang/include/clang/Basic/LangOptions.h:747
+  /// Return difference with the given option set.
+  FPOptionsOverride diffWith(const FPOptions &Base);
+

rjmccall wrote:
> Can you make direction more obvious in the method name?  `diffFrom` would 
> make it clear that the result, applied to the base, yields `this`.
I renamed this method to `getChanges`. I am not sure it becomes better. May be 
`getChangesFrom` or `getDiffFrom`? Any suggestion is welcome.



Comment at: clang/include/clang/Sema/ScopeInfo.h:77-78
 
-  CompoundScopeInfo(bool IsStmtExpr) : IsStmtExpr(IsStmtExpr) {}
+  /// FP options at the beginning of the compound statement, prior to
+  /// any pragma.
+  FPOptions FPFeatures;

rjmccall wrote:
> aaron.ballman wrote:
> > sepavloff wrote:
> > > aaron.ballman wrote:
> > > > So these are the initial FPOptions inherited by the scope from its 
> > > > surrounding context? And it's never updated by a pragma?
> > > Yes, this FPOption is used to calculate the effect of pragmas in the 
> > > compound statement as a difference with FPOptions stored in Sema, so that 
> > > CompoundStmt keeps only FP features that are changed in it.
> > It might make sense to rename this to `OriginalFPFeatures` or 
> > `InitialFPFeatures` or something like that, to make it more clear that this 
> > field is not updated as we process the rest of the compound statement. WDYT?
> Yeah, I agree; this name makes it sound like the current, live set of 
> features, even if the comment explains that it isn't.
It makes sense. Renamed to `InitialFPFeatures`.



Comment at: clang/lib/AST/StmtPrinter.cpp:216
+LangOptions::RoundingMode RM = FPO.getConstRoundingModeOverride();
+if (RM != llvm::RoundingMode::Dynamic) {
+  Indent() << "#pragma STDC FENV_ROUND ";

aaron.ballman wrote:
> Why is this not handled as well and print out `FE_DYNAMIC`?
Initially it was used to prevent extra `FENV_ROUND FE_DYNAMIC` pragma in the 
case when only `FENV_ACCESS` was specified. However after landing D126364 there 
is no need for that.  Now `FE_DYNAMIC` is treated similar to other values.



Comment at: clang/lib/Basic/LangOptions.cpp:214
+OverrideMask |= NAME##Mask;
+#include "clang/Basic/FPOptions.def"
+  return FPOptionsOverride(*this, OverrideMask);

rjmccall wrote:
> sepavloff wrote:
> > rjmccall wrote:
> > > Hmm.  If we can assume that all of the options are single bits (which 
> > > this is doing), then this algorithm is basically `FPOptions::storage_type 
> > > OverrideMask = (Value ^ Base.Value);`, which makes this cheap enough to 
> > > be defined inline in the header.
> > `FPContractMode`, `ConstRoundingMode`, `SpecifiedExceptionMode` and 
> > `FPEvalMethod` occupy more than one bit: 
> > https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Basic/FPOptions.def.
> Oh, I see.  I wasn't reasoning correctly about how this is a mask and not a 
> value.
> 
> In non-LTO builds, we'll have to actually do this call when leaving every 
> scope.  It's a minor overhead, but it'd be nice to avoid.  Please do the fast 
> path in an inline implementation and then put this slow path out of line, in 
> a private method named `diffFromSlow` or something like that.
Implemented slow and inline versions. The later is defined after definition of 
`FPOptionsOverride` in this file.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123952

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


[PATCH] D128182: [NFC] Switch FloatModeKind enum class to use bitmask enums

2022-06-28 Thread Jolanta Jensen via Phabricator via cfe-commits
jolanta.jensen added inline comments.



Comment at: clang/include/clang/Basic/TargetInfo.h:225-226
   unsigned HasAlignMac68kSupport : 1;
-  unsigned RealTypeUsesObjCFPRetMask : (int)FloatModeKind::Last + 1;
+  unsigned RealTypeUsesObjCFPRetMask
+  : (int)FloatModeKind::LLVM_BITMASK_LARGEST_ENUMERATOR;
   unsigned ComplexLongDoubleUsesFP2Ret : 1;

aaron.ballman wrote:
> Whoops, I missed this (thanks @shafik for asking me about it in private)!
> 
> I believe the original code was setting the field width to be `1 << 5` bits 
> wide instead of specifying it as being 6 bits wide.
Oh dear, I was to replace log2 with bitWidth and I only did half the job. 
Thanks for spotting!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128182

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


[PATCH] D128645: Update developer policy.

2022-06-28 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 added inline comments.



Comment at: llvm/docs/DeveloperPolicy.rst:88
+#. Patches should be unified diffs with "infinte context" (i.e. using something
+   like `git diff -U 99 main`).
+

vext01 wrote:
> xbolva00 wrote:
> > vext01 wrote:
> > > xbolva00 wrote:
> > > > main is weird example here imho.
> > > How comes? The docs told me to make my diffs off `main`, so that's what 
> > > you'd be diffing against typically. No?
> > Ah, okay. I usually use it without it.
> That would mean you haven't committed your changes, and `git clang-fomat` 
> wont work in that case, so committing is best IMHO.
I use arc land :)


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

https://reviews.llvm.org/D128645

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


[clang] a2095d1 - Allow mangled names in sanitizer clang IR gen tests.

2022-06-28 Thread Mitch Phillips via cfe-commits

Author: Mitch Phillips
Date: 2022-06-28T09:27:43-07:00
New Revision: a2095d1aff847ab7f7035744fb718c32cf680a01

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

LOG: Allow mangled names in sanitizer clang IR gen tests.

Looks like with https://reviews.llvm.org/D127911, Windows emits more
globals with mangled names into the IR. Relax the tests in order to
allow these mangled names.

Added: 


Modified: 
clang/test/CodeGen/asan-globals.cpp
clang/test/CodeGen/hwasan-globals.cpp

Removed: 




diff  --git a/clang/test/CodeGen/asan-globals.cpp 
b/clang/test/CodeGen/asan-globals.cpp
index 74c461d1cafff..a3b786fe2e5d3 100644
--- a/clang/test/CodeGen/asan-globals.cpp
+++ b/clang/test/CodeGen/asan-globals.cpp
@@ -30,23 +30,23 @@ void func() {
 // GLOBS: @{{.*}}dyn_init_global{{.*}} ={{.*}} global {{.*}}, 
sanitize_address_dyninit
 // GLOBS-NOT: no_sanitize_address
 
-// GLOBS: @attributed_global = global {{.*}} no_sanitize_address
-// GLOBS: @disable_instrumentation_global = global {{.*}} 
no_sanitize_address
-// GLOBS: @ignorelisted_global = global {{.*}} no_sanitize_address
+// GLOBS: @{{.*}}attributed_global{{.*}} ={{.*}} global {{.*}} 
no_sanitize_address
+// GLOBS: @{{.*}}disable_instrumentation_global{{.*}} ={{.*}} global 
{{.*}} no_sanitize_address
+// GLOBS: @{{.*}}ignorelisted_global{{.*}} ={{.*}} global {{.*}} 
no_sanitize_address
 
-// ASAN: sectioned_global{{.*}} global { i32, [28 x i8] }{{.*}}, align 32
+// ASAN: @{{.*}}sectioned_global{{.*}} ={{.*}} global { i32, [28 x i8] 
}{{.*}}, align 32
 // ASAN-NOT: no_sanitize_address
-// ASAN: @__special_global{{.*}} global { i32, [28 x i8] }{{.*}}, align 32
+// ASAN: @{{.*}}__special_global{{.*}} ={{.*}} global { i32, [28 x i8] 
}{{.*}}, align 32
 // ASAN-NOT: no_sanitize_address
 
 /// Note: No attribute is added by the IR pass, but the type didn't change, so
 /// that checks our assertions that the globals didn't get instrumented.
-// KASAN:sectioned_global{{.*}} global i32 {{.*}}
-// KASAN:@__special_global{{.*}} global i32 {{.*}}
+// KASAN:@{{.*}}sectioned_global{{.*}} ={{.*}} global i32 {{.*}}
+// KASAN:@{{.*}}__special_global{{.*}} ={{.*}} global i32 {{.*}}
 
-// GLOBS: @{{[^ ]*}}static_var{{[^ ]*}} = internal global {{.*}}
+// GLOBS: @{{[^ ]*}}static_var{{[^ ]*}} ={{.*}} global {{.*}}
 // GLOBS-NOT: no_sanitize_address
-// GLOBS: @{{.*}} = internal constant {{.*}}"Hello, world!{{.*}}
+// GLOBS: @{{.*}} = {{.*}}c"Hello, world!\00"
 // GLOBS-NOT: no_sanitize_address
 
 /// Without -fasynchronous-unwind-tables, ctor and dtor get the uwtable 
attribute.
@@ -72,14 +72,14 @@ void func() {
 // UWTABLE: attributes #[[#ATTR]] = { nounwind uwtable }
 // UWTABLE: ![[#]] = !{i32 7, !"uwtable", i32 2}
 
-// IGNORELIST-SRC: @extra_global = global {{.*}}
+// IGNORELIST-SRC: @{{.*}}extra_global{{.*}} ={{.*}} global
 // IGNORELIST-SRC-NOT: no_sanitize_address
-// IGNORELIST-SRC: @global = global {{.*}} no_sanitize_address
-// IGNORELIST-SRC: @dyn_init_global = global {{.*}} no_sanitize_address
-// IGNORELIST-SRC: @attributed_global = global {{.*}} no_sanitize_address
-// IGNORELIST-SRC: @disable_instrumentation_global = global {{.*}} 
no_sanitize_address
-// IGNORELIST-SRC: @ignorelisted_global = global {{.*}} no_sanitize_address
-// IGNORELIST-SRC: @sectioned_global = global {{.*}} no_sanitize_address
-// IGNORELIST-SRC: @__special_global = global {{.*}} no_sanitize_address
-// IGNORELIST-SRC: @{{[^ ]*}}static_var{{[^ ]*}} = internal global {{.*}} 
no_sanitize_address
-// IGNORELIST-SRC: @.str = {{.*}} constant {{.*}}"Hello, world!{{.*}} 
no_sanitize_address
+// IGNORELIST-SRC: @{{.*}}global{{.*}} ={{.*}} global {{.*}} 
no_sanitize_address
+// IGNORELIST-SRC: @{{.*}}dyn_init_global{{.*}} ={{.*}} global {{.*}} 
no_sanitize_address
+// IGNORELIST-SRC: @{{.*}}attributed_global{{.*}} ={{.*}} global {{.*}} 
no_sanitize_address
+// IGNORELIST-SRC: @{{.*}}disable_instrumentation_global{{.*}} ={{.*}} 
global {{.*}} no_sanitize_address
+// IGNORELIST-SRC: @{{.*}}ignorelisted_global{{.*}} ={{.*}} global {{.*}} 
no_sanitize_address
+// IGNORELIST-SRC: @{{.*}}sectioned_global{{.*}} ={{.*}} global {{.*}} 
no_sanitize_address
+// 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

diff  --git a/clang/test/CodeGen/hwasan-globals.cpp 
b/clang/test/CodeGen/hwasan-globals.cpp
index a81bcb7110233..d9f2e699c2eff 100644
--- a/clang/test/CodeGen/hwasan-globals.cpp
+++ b/clang/test/CodeGen/hwasan-globa

[PATCH] D128726: [RISCV][NFC] Move static global variables into static variable in function.

2022-06-28 Thread Jessica Clarke via Phabricator via cfe-commits
jrtc27 added a comment.

The commit message is poor, because the problem is not the use of static 
globals, it's the use of globals that have constructors. Moving them to be 
static function-scoped variables doesn't change the fact that they still have 
static duration; you change the scope of them but not their storage. 
Implementations can defer their initialisation until the first time the 
function is called, but do not have to. Clang, GCC and MSVC all do in fact 
perform lazy initialisation (with all the overhead that comes with to make it 
thread-safe and exception-safe) so maybe this is fine in practice. Is there 
precedent for this?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128726

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


[PATCH] D128645: Update developer policy.

2022-06-28 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

The changes LGTM, but you should wait a bit before landing in case other 
reviewers/subscribers want to chime in if they still have opinions.




Comment at: llvm/docs/DeveloperPolicy.rst:88
+#. Patches should be unified diffs with "infinte context" (i.e. using something
+   like `git diff -U 99 main`).
+

xbolva00 wrote:
> vext01 wrote:
> > xbolva00 wrote:
> > > vext01 wrote:
> > > > xbolva00 wrote:
> > > > > main is weird example here imho.
> > > > How comes? The docs told me to make my diffs off `main`, so that's what 
> > > > you'd be diffing against typically. No?
> > > Ah, okay. I usually use it without it.
> > That would mean you haven't committed your changes, and `git clang-fomat` 
> > wont work in that case, so committing is best IMHO.
> I use arc land :)
FWIW, I also never put `main` explicitly on my diff lines; and I don't use 
`arc` (I just use `git diff`). Not everyone's workflow involves carrying around 
git branches for everything. That said, I don't have an issue with being 
explicit here, either.


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

https://reviews.llvm.org/D128645

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


[PATCH] D108469: Improve handling of static assert messages.

2022-06-28 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM! The precommit CI failures appear to be unrelated as best I can tell.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108469

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


[PATCH] D123878: [AMDGPU] Add remarks to output some resource usage

2022-06-28 Thread Scott Linder via Phabricator via cfe-commits
scott.linder added a comment.

I will let others comment, but I think this is a perfectly reasonable 
alternative, and I much prefer using indentation over the delimiter-remark 
approach. LGTM, assuming nobody else objects


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123878

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


[PATCH] D128202: [clangd] Include "final" when printing class declaration

2022-06-28 Thread Tom Praschan via Phabricator via cfe-commits
tom-anders updated this revision to Diff 440676.
tom-anders added a comment.

Check for FinalAttr instead of using isEffectivelyFinal()


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128202

Files:
  clang-tools-extra/clangd/unittests/HoverTests.cpp
  clang/lib/AST/DeclPrinter.cpp


Index: clang/lib/AST/DeclPrinter.cpp
===
--- clang/lib/AST/DeclPrinter.cpp
+++ clang/lib/AST/DeclPrinter.cpp
@@ -1007,6 +1007,12 @@
 }
   }
 
+  if (auto *Def = D->getDefinition()) {
+  if (D->hasAttr()) {
+  Out << " final";
+  }
+  }
+
   if (D->isCompleteDefinition()) {
 // Print the base classes
 if (D->getNumBases()) {
Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -198,7 +198,7 @@
 typename = char,
 int = 0,
 bool Q = false,
-class... Ts> class Foo {};
+class... Ts> class Foo final {};
   template  class T>
   [[F^oo]] foo;
   )cpp",
@@ -209,7 +209,7 @@
  HI.Definition =
  R"cpp(template  class C, typename = 
char, int = 0,
   bool Q = false, class... Ts>
-class Foo {})cpp";
+class Foo final {})cpp";
  HI.TemplateParameters = {
  {{"template  class"},
   std::string("C"),


Index: clang/lib/AST/DeclPrinter.cpp
===
--- clang/lib/AST/DeclPrinter.cpp
+++ clang/lib/AST/DeclPrinter.cpp
@@ -1007,6 +1007,12 @@
 }
   }
 
+  if (auto *Def = D->getDefinition()) {
+  if (D->hasAttr()) {
+  Out << " final";
+  }
+  }
+
   if (D->isCompleteDefinition()) {
 // Print the base classes
 if (D->getNumBases()) {
Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -198,7 +198,7 @@
 typename = char,
 int = 0,
 bool Q = false,
-class... Ts> class Foo {};
+class... Ts> class Foo final {};
   template  class T>
   [[F^oo]] foo;
   )cpp",
@@ -209,7 +209,7 @@
  HI.Definition =
  R"cpp(template  class C, typename = char, int = 0,
   bool Q = false, class... Ts>
-class Foo {})cpp";
+class Foo final {})cpp";
  HI.TemplateParameters = {
  {{"template  class"},
   std::string("C"),
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D127911: Delete 'llvm.asan.globals' for global metadata.

2022-06-28 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added a comment.

In D127911#3614242 , @thakis wrote:

> Looks like this breaks check-clang on windows: 
> http://45.33.8.238/win/61067/step_7.txt
>
> Please take a look and revert for now if it takes a while to fix.

Thanks. Added a2095d1aff84 
. Bot 
looks green now: http://45.33.8.238/win/61118/summary.html


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127911

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


[PATCH] D128571: [X86] Support `_Float16` on SSE2 and up

2022-06-28 Thread Ben Langmuir via Phabricator via cfe-commits
benlangmuir added a comment.

This broke some compiler-rt tests on Darwin:
https://green.lab.llvm.org/green/job/clang-stage1-RA/29920/

  Test Result (3 failures / +3)
  Builtins-x86_64-darwin.Builtins-x86_64-darwin.extendhfsf2_test.c
  Builtins-x86_64-darwin.Builtins-x86_64-darwin.truncdfhf2_test.c
  Builtins-x86_64-darwin.Builtins-x86_64-darwin.truncsfhf2_test.c


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128571

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


[PATCH] D127898: [clang][dataflow] Add API to separate analysis from diagnosis

2022-06-28 Thread Sam Estep via Phabricator via cfe-commits
samestep updated this revision to Diff 440687.
samestep added a comment.

- Implement Gábor's suggestion
- Merge branch 'main' into diagnose-api


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127898

Files:
  
clang/include/clang/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.h
  clang/include/clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h
  clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
  clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
  clang/unittests/Analysis/FlowSensitive/TestingSupport.h
  clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
@@ -11,9 +11,11 @@
 #include "TestingSupport.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
-#include "clang/Analysis/FlowSensitive/SourceLocationsLattice.h"
+#include "clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h"
+#include "clang/Basic/SourceLocation.h"
 #include "clang/Tooling/Tooling.h"
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Support/Error.h"
 #include "gmock/gmock.h"
@@ -26,8 +28,7 @@
 using namespace dataflow;
 using namespace test;
 
-using ::testing::Pair;
-using ::testing::UnorderedElementsAre;
+using ::testing::ContainerEq;
 
 // FIXME: Move header definitions in separate file(s).
 static constexpr char CSDtdDefHeader[] = R"(
@@ -1180,13 +1181,6 @@
 } // namespace base
 )";
 
-/// Converts `L` to string.
-static std::string ConvertToString(const SourceLocationsLattice &L,
-   const ASTContext &Ctx) {
-  return L.getSourceLocations().empty() ? "safe"
-: "unsafe: " + DebugString(L, Ctx);
-}
-
 /// Replaces all occurrences of `Pattern` in `S` with `Replacement`.
 static void ReplaceAllOccurrences(std::string &S, const std::string &Pattern,
   const std::string &Replacement) {
@@ -1207,18 +1201,14 @@
 class UncheckedOptionalAccessTest
 : public ::testing::TestWithParam {
 protected:
-  template 
-  void ExpectLatticeChecksFor(std::string SourceCode,
-  LatticeChecksMatcher MatchesLatticeChecks) {
-ExpectLatticeChecksFor(SourceCode, ast_matchers::hasName("target"),
-   MatchesLatticeChecks);
+  void ExpectDiagnosticsFor(std::string SourceCode) {
+ExpectDiagnosticsFor(SourceCode, ast_matchers::hasName("target"));
   }
 
 private:
-  template 
-  void ExpectLatticeChecksFor(std::string SourceCode,
-  FuncDeclMatcher FuncMatcher,
-  LatticeChecksMatcher MatchesLatticeChecks) {
+  template 
+  void ExpectDiagnosticsFor(std::string SourceCode,
+FuncDeclMatcher FuncMatcher) {
 ReplaceAllOccurrences(SourceCode, "$ns", GetParam().NamespaceName);
 ReplaceAllOccurrences(SourceCode, "$optional", GetParam().TypeName);
 
@@ -1245,27 +1235,48 @@
 )");
 const tooling::FileContentMappings FileContents(Headers.begin(),
 Headers.end());
+UncheckedOptionalAccessModelOptions Options{
+/*IgnoreSmartPointerDereference=*/true};
+std::vector Diagnostics;
 llvm::Error Error = checkDataflow(
 SourceCode, FuncMatcher,
-[](ASTContext &Ctx, Environment &) {
-  return UncheckedOptionalAccessModel(
-  Ctx, UncheckedOptionalAccessModelOptions{
-   /*IgnoreSmartPointerDereference=*/true});
+[Options](ASTContext &Ctx, Environment &) {
+  return UncheckedOptionalAccessModel(Ctx, Options);
+},
+[Options, &Diagnostics](ASTContext &Ctx) {
+  UncheckedOptionalAccessDiagnosis Diagnosis(Ctx, Options);
+  return [&Diagnostics, Diagnosis = std::move(Diagnosis)](
+ const Stmt *Stmt,
+ const TypeErasedDataflowAnalysisState &State) mutable {
+auto StmtDiagnostics = Diagnosis.diagnose(Stmt, State.Env);
+std::move(StmtDiagnostics.begin(), StmtDiagnostics.end(),
+  std::back_inserter(Diagnostics));
+  };
 },
-[&MatchesLatticeChecks](
-llvm::ArrayRef>>
-CheckToLatticeMap,
-ASTContext &Ctx) {
-  // FIXME: Consider using a matcher instead of translating
-  // `CheckToLatticeMap` to `CheckToStringifiedLatticeMap`.
-  std::vector>
-  CheckToStringifiedLatticeMap;
-  for (const auto &E : C

[clang] eab2a06 - Revert "Reland "[X86] Support `_Float16` on SSE2 and up""

2022-06-28 Thread Ben Langmuir via cfe-commits

Author: Ben Langmuir
Date: 2022-06-28T10:59:03-07:00
New Revision: eab2a06f0fde51eee6b1526bd301d60c4cc9b050

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

LOG: Revert "Reland "[X86] Support `_Float16` on SSE2 and up""

Broke compiler-rt on Darwin: 
https://green.lab.llvm.org/green/job/clang-stage1-RA/29920/

This reverts commit 527ef8ca981e88a35758c0e4143be6853ea26dfc.

Added: 
clang/test/CodeGen/X86/avx512fp16-complex.c

Modified: 
clang/docs/LanguageExtensions.rst
clang/docs/ReleaseNotes.rst
clang/lib/Basic/Targets/X86.cpp
clang/test/Sema/Float16.c
clang/test/Sema/conversion-target-dep.c
clang/test/SemaCXX/Float16.cpp
compiler-rt/test/builtins/CMakeLists.txt

Removed: 
clang/test/CodeGen/X86/Float16-arithmetic.c
clang/test/CodeGen/X86/Float16-complex.c



diff  --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 1bac2aee84bd9..af697fafd8c41 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -743,13 +743,7 @@ targets pending ABI standardization:
 * 64-bit ARM (AArch64)
 * AMDGPU
 * SPIR
-* X86 (see below)
-
-On X86 targets, ``_Float16`` is supported as long as SSE2 is available, which
-includes all 64-bit and all recent 32-bit processors. When the target supports
-AVX512-FP16, ``_Float16`` arithmetic is performed using that native support.
-Otherwise, ``_Float16`` arithmetic is performed by promoting to ``float``,
-performing the operation, and then truncating to ``_Float16``.
+* X86 (Only available under feature AVX512-FP16)
 
 ``_Float16`` will be supported on more targets as they define ABIs for it.
 

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 733f10a7e4d1a..3e29987ad2631 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -514,9 +514,6 @@ X86 Support in Clang
 
 - Support ``-mharden-sls=[none|all|return|indirect-jmp]`` for straight-line
   speculation hardening.
-- Support for the ``_Float16`` type has been added for all targets with SSE2.
-  When AVX512-FP16 is not available, arithmetic on ``_Float16`` is emulated
-  using ``float``.
 
 DWARF Support in Clang
 --

diff  --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp
index 0b3d87837ef6a..b83b3517ddf90 100644
--- a/clang/lib/Basic/Targets/X86.cpp
+++ b/clang/lib/Basic/Targets/X86.cpp
@@ -239,6 +239,7 @@ bool 
X86TargetInfo::handleTargetFeatures(std::vector &Features,
   HasAVX512ER = true;
 } else if (Feature == "+avx512fp16") {
   HasAVX512FP16 = true;
+  HasFloat16 = true;
 } else if (Feature == "+avx512pf") {
   HasAVX512PF = true;
 } else if (Feature == "+avx512dq") {
@@ -354,9 +355,6 @@ bool 
X86TargetInfo::handleTargetFeatures(std::vector &Features,
.Default(NoSSE);
 SSELevel = std::max(SSELevel, Level);
 
-// Turn on _float16 for x86 (feature sse2)
-HasFloat16 = SSELevel >= SSE2;
-
 MMX3DNowEnum ThreeDNowLevel = llvm::StringSwitch(Feature)
   .Case("+3dnowa", AMD3DNowAthlon)
   .Case("+3dnow", AMD3DNow)

diff  --git a/clang/test/CodeGen/X86/Float16-arithmetic.c 
b/clang/test/CodeGen/X86/Float16-arithmetic.c
deleted file mode 100644
index 726da22a22b08..0
--- a/clang/test/CodeGen/X86/Float16-arithmetic.c
+++ /dev/null
@@ -1,29 +0,0 @@
-// RUN: %clang_cc1 -triple  x86_64-unknown-unknown \
-// RUN: -emit-llvm -o - %s  | FileCheck %s --check-prefixes=CHECK
-
-// CHECK-NOT: fpext
-// CHECK-NOT: fptrunc
-
-_Float16 add1(_Float16 a, _Float16 b) {
-  return a + b;
-}
-
-_Float16 add2(_Float16 a, _Float16 b, _Float16 c) {
-  return a + b + c;
-}
-
-_Float16 div(_Float16 a, _Float16 b) {
-  return a / b;
-}
-
-_Float16 mul(_Float16 a, _Float16 b) {
-  return a * b;
-}
-
-_Float16 add_and_mul1(_Float16 a, _Float16 b, _Float16 c, _Float16 d) {
-  return a * b + c * d;
-}
-
-_Float16 add_and_mul2(_Float16 a, _Float16 b, _Float16 c, _Float16 d) {
-  return (a - 6 * b) + c;
-}

diff  --git a/clang/test/CodeGen/X86/Float16-complex.c 
b/clang/test/CodeGen/X86/avx512fp16-complex.c
similarity index 96%
rename from clang/test/CodeGen/X86/Float16-complex.c
rename to clang/test/CodeGen/X86/avx512fp16-complex.c
index ebb290c976e7d..8a6b50eb0056b 100644
--- a/clang/test/CodeGen/X86/Float16-complex.c
+++ b/clang/test/CodeGen/X86/avx512fp16-complex.c
@@ -1,5 +1,4 @@
 // RUN: %clang_cc1 %s -O0 -emit-llvm -triple x86_64-unknown-unknown 
-target-feature +avx512fp16 -o - | FileCheck %s --check-prefix=X86
-// RUN: %clang_cc1 %s -O0 -emit-llvm -triple x86_64-unknown-unknown -o - | 
FileCheck %s --check-prefix=X86
 
 _Float16 _Complex add_half_rr(_Float16 a, _Float16 b) {
   // X86-LABEL:

[PATCH] D128571: [X86] Support `_Float16` on SSE2 and up

2022-06-28 Thread Ben Langmuir via Phabricator via cfe-commits
benlangmuir added a comment.

Reverted in eab2a06f0fde 
 due to 
the Darwin test failures.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128571

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


[PATCH] D127898: [clang][dataflow] Add API to separate analysis from diagnosis

2022-06-28 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel added inline comments.



Comment at: 
clang/include/clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h:126
+std::function
+PostVisitStmt = nullptr);
 

Please update comment to mention this new param (and that its optional)



Comment at: clang/unittests/Analysis/FlowSensitive/TestingSupport.h:65
 
-// Runs dataflow on the body of the function that matches `func_matcher` in 
code
-// snippet `code`. Requires: `Analysis` contains a type `Lattice`.
+struct AnalysisResults {
+  AnalysisResults(

nit: since this includes both inputs and results, maybe `AnalysisData`?



Comment at: clang/unittests/Analysis/FlowSensitive/TestingSupport.h:123
   auto Analysis = MakeAnalysis(Context, Env);
+  auto PostVisitStmt = MakePostVisitStmt ? MakePostVisitStmt(Context) : 
nullptr;
 

nit: i prefer explicit comparisons, so `MakePostVisitStmt != nullptr`.



Comment at: clang/unittests/Analysis/FlowSensitive/TestingSupport.h:161
+  return checkDataflow(
+  Code, std::move(FuncMatcher), std::move(MakeAnalysis), nullptr,
+  [&Expectations](AnalysisResults AnalysisResults) {





Comment at: clang/unittests/Analysis/FlowSensitive/TestingSupport.h:172-191
+std::vector> Results;
+for (const CFGBlock *Block : AnalysisResults.CFCtx.getCFG()) {
+  // Skip blocks that were not evaluated.
+  if (!AnalysisResults.BlockStates[Block->getBlockID()])
+continue;
+
+  transferBlock(

any chance that this could be folded into `MakePostVisitStmt`?



Comment at: 
clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp:1248
+  UncheckedOptionalAccessDiagnosis Diagnosis(Ctx, Options);
+  return [&Diagnostics, Diagnosis = std::move(Diagnosis)](
+ const Stmt *Stmt,




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127898

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


[PATCH] D128745: [Sema] fix trailing parameter pack handling for function template partial ordering

2022-06-28 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen created this revision.
ychen added reviewers: rsmith, aaron.ballman.
Herald added a project: All.
ychen requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D128745

Files:
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/test/CXX/drs/dr6xx.cpp


Index: clang/test/CXX/drs/dr6xx.cpp
===
--- clang/test/CXX/drs/dr6xx.cpp
+++ clang/test/CXX/drs/dr6xx.cpp
@@ -1086,15 +1086,12 @@
 template  struct A {};
 template  void f(U, A *p = 0); // 
expected-note {{candidate}}
 template  int &f(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 &r = 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}}
 }
   }
 
Index: clang/lib/Sema/SemaTemplateDeduction.cpp
===
--- clang/lib/Sema/SemaTemplateDeduction.cpp
+++ clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -5181,13 +5181,21 @@
   if (!Better1 && !Better2) // Neither is better than the other
 return JudgeByConstraints();
 
-  // 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,
-  // but for now we attempt to maintain compatibility.
+  const unsigned NumParams1 = FT1->getTemplatedDecl()->getNumParams();
+  const unsigned NumParams2 = FT2->getTemplatedDecl()->getNumParams();
+
+  // C++ [temp.deduct.partial]p11:
+  //   ... and if G has a trailing function parameter pack for which F does not
+  //   have a corresponding parameter, and if F does not have a trailing
+  //   function parameter pack, then F is more specialized than G.
   bool Variadic1 = isVariadicFunctionTemplate(FT1);
   bool Variadic2 = isVariadicFunctionTemplate(FT2);
-  if (Variadic1 != Variadic2)
-return Variadic1? FT2 : FT1;
+  if (Variadic1 != Variadic2) {
+if (Variadic1 && NumParams1 > NumParams2)
+  return FT2;
+if (Variadic2 && NumParams2 > NumParams1)
+  return FT1;
+  }
 
   return JudgeByConstraints();
 }


Index: clang/test/CXX/drs/dr6xx.cpp
===
--- clang/test/CXX/drs/dr6xx.cpp
+++ clang/test/CXX/drs/dr6xx.cpp
@@ -1086,15 +1086,12 @@
 template  struct A {};
 template  void f(U, A *p = 0); // expected-note {{candidate}}
 template  int &f(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 &r = 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}}
 }
   }
 
Index: clang/lib/Sema/SemaTemplateDeduction.cpp
===
--- clang/lib/Sema/SemaTemplateDeduction.cpp
+++ clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -5181,13 +5181,21 @@
   if (!Better1 && !Better2) // Neither is better than the other
 return JudgeByConstraints();
 
-  // 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,
-  // but for now we attempt to maintain compatibility.
+  const unsigned NumParams1 = FT1->getTemplatedDecl()->getNumParams();
+  const unsigned NumParams2 = FT2->getTemplatedDecl()->getNumParams();
+
+  // C++ [temp.deduct.partial]p11:
+  //   ... and if G has a trailing function parameter pack for which F does not
+  //   have a corresponding parameter, and if F does not have a trailing
+  //   function parameter pack, then F is more specialized than G.
   bool Variadic1 = isVariadicFunctionTemplate(FT1);
   bool Variadic2 = isVariadicFunctionTemplate(FT2);
-  if (Variadic1 != Variadic2)
-return Variadic1? FT2 : FT1;
+  if (Variadic1 != Variadic2) {
+if (Variadic1 && NumParams1 > NumParams2)
+  return FT2;
+if (Variadic2 && NumParams2 > NumParams1)
+  return FT1;
+  }
 
   return JudgeBy

  1   2   3   >