[PATCH] D114317: [clang-tidy][WIP] Do not run perfect alias checks

2021-12-03 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added a comment.

Kind ping to reviewers, I mostly want to know if you agree with the general 
direction so I can go ahead and implement the rest of the patch. It's a big 
change (replace all check registrations with the macro) so I'd like to avoid 
extra work if you are strongly against it.

@aaron.ballman I understand you are super busy and don't want to take any more 
time than needed from you. I'd just love to hear your thoughts about the two 
missing points that we discussed in the RFC. Nobody else seems to have raised 
similar concerns about it.

Really appreciate your time!


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

https://reviews.llvm.org/D114317

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


[PATCH] D114949: [clangd] IncludeCleaner: Do not require forward declarations of RecordDecls when definition is available

2021-12-03 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet accepted this revision.
kadircet added a comment.
This revision is now accepted and ready to land.

thanks!




Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:127
+// declared multiple times. The most common two cases are:
+// - Definition available in TU, only mark that one as usage. rest is
+//   likely to be unnecessary. this might result in false positives when an

i know it was me who didn't capitalize, but can you capitalize the first words 
:D
s/rest/Rest
s/this/This (line below)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114949

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


[PATCH] D112453: [Sema] When dereferencing a pointer of dependent type, infer the result type.

2021-12-03 Thread Clement Courbet via Phabricator via cfe-commits
courbet added a comment.

ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112453

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


[PATCH] D114949: [clangd] IncludeCleaner: Do not require forward declarations of RecordDecls when definition is available

2021-12-03 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev added a comment.

In D114949#3169074 , @kadircet wrote:

> thanks!

Aww, sorry, I capitalized/reformatted parts of them but missed the rest :D


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114949

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


[PATCH] D114949: [clangd] IncludeCleaner: Do not require forward declarations of RecordDecls when definition is available

2021-12-03 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 391566.
kbobyrev added a comment.

Fix typos.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114949

Files:
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp


Index: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
===
--- clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -39,10 +39,10 @@
   "class ^X;",
   "X *y;",
   },
-  // FIXME(kirillbobyrev): When definition is available, we don't need to
-  // mark forward declarations as used.
+  // When definition is available, we don't need to mark forward
+  // declarations as used.
   {
-  "class ^X {}; class ^X;",
+  "class ^X {}; class X;",
   "X *y;",
   },
   // We already have forward declaration in the main file, the other
@@ -51,17 +51,24 @@
   "class ^X {}; class X;",
   "class X; X *y;",
   },
+  // Nested class definition can occur outside of the parent class
+  // definition. Bar declaration should be visible to its definition but
+  // it will always be because we will mark Foo definition as used.
+  {
+  "class ^Foo { class Bar; };",
+  "class Foo::Bar {};",
+  },
   // TypedefType and UsingDecls
   {
   "using ^Integer = int;",
   "Integer x;",
   },
   {
-  "namespace ns { struct ^X; struct ^X {}; }",
-  "using ns::X;",
+  "namespace ns { void ^foo(); void ^foo() {} }",
+  "using ns::foo;",
   },
   {
-  "namespace ns { struct X; struct X {}; }",
+  "namespace ns { void foo(); void foo() {}; }",
   "using namespace ns;",
   },
   {
@@ -88,8 +95,8 @@
   },
   // Redecls
   {
-  "class ^X; class ^X{}; class ^X;",
-  "X *y;",
+  "void ^foo(); void ^foo() {} void ^foo();",
+  "void bar() { foo(); }",
   },
   // Constructor
   {
Index: clang-tools-extra/clangd/IncludeCleaner.cpp
===
--- clang-tools-extra/clangd/IncludeCleaner.cpp
+++ clang-tools-extra/clangd/IncludeCleaner.cpp
@@ -122,16 +122,20 @@
   void add(const Decl *D) {
 if (!D || !isNew(D->getCanonicalDecl()))
   return;
-// If we see a declaration in the mainfile, skip all non-definition decls.
-// We only do this for classes because forward declarations are common and
-// we don't want to include every header that forward-declares the symbol
-// because they're often unrelated.
+// Special case RecordDecls, as it is common for them to be forward
+// declared multiple times. The most common two cases are:
+// - Definition available in TU, only mark that one as usage. The rest is
+//   likely to be unnecessary. This might result in false positives when an
+//   internal definition is visible.
+// - There's a forward declaration in the main file, no need for other
+//   redecls.
 if (const auto *RD = llvm::dyn_cast(D)) {
-  if (SM.isInMainFile(RD->getMostRecentDecl()->getBeginLoc())) {
-if (const auto *Definition = RD->getMostRecentDecl()->getDefinition())
-  Result.insert(Definition->getLocation());
+  if (const auto *Definition = RD->getDefinition()) {
+Result.insert(Definition->getLocation());
 return;
   }
+  if (SM.isInMainFile(RD->getMostRecentDecl()->getLocation()))
+return;
 }
 for (const Decl *Redecl : D->redecls())
   Result.insert(Redecl->getLocation());


Index: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
===
--- clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -39,10 +39,10 @@
   "class ^X;",
   "X *y;",
   },
-  // FIXME(kirillbobyrev): When definition is available, we don't need to
-  // mark forward declarations as used.
+  // When definition is available, we don't need to mark forward
+  // declarations as used.
   {
-  "class ^X {}; class ^X;",
+  "class ^X {}; class X;",
   "X *y;",
   },
   // We already have forward declaration in the main file, the other
@@ -51,17 +51,24 @@
   "class ^X {}; class X;",
   "class X; X *y;",
   },
+  // Nested class definition can occur outside of the parent class
+  // definition. Bar declaration should be visible to its definition but
+  // it will always be because we will mark Foo definition as used.
+  {
+  "class ^Foo { class Bar; };",
+  "class Foo::Bar {};",
+  

[PATCH] D114949: [clangd] IncludeCleaner: Do not require forward declarations of RecordDecls when definition is available

2021-12-03 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 391567.
kbobyrev marked an inline comment as done.
kbobyrev added a comment.

Improve wording.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114949

Files:
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp


Index: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
===
--- clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -39,10 +39,10 @@
   "class ^X;",
   "X *y;",
   },
-  // FIXME(kirillbobyrev): When definition is available, we don't need to
-  // mark forward declarations as used.
+  // When definition is available, we don't need to mark forward
+  // declarations as used.
   {
-  "class ^X {}; class ^X;",
+  "class ^X {}; class X;",
   "X *y;",
   },
   // We already have forward declaration in the main file, the other
@@ -51,17 +51,24 @@
   "class ^X {}; class X;",
   "class X; X *y;",
   },
+  // Nested class definition can occur outside of the parent class
+  // definition. Bar declaration should be visible to its definition but
+  // it will always be because we will mark Foo definition as used.
+  {
+  "class ^Foo { class Bar; };",
+  "class Foo::Bar {};",
+  },
   // TypedefType and UsingDecls
   {
   "using ^Integer = int;",
   "Integer x;",
   },
   {
-  "namespace ns { struct ^X; struct ^X {}; }",
-  "using ns::X;",
+  "namespace ns { void ^foo(); void ^foo() {} }",
+  "using ns::foo;",
   },
   {
-  "namespace ns { struct X; struct X {}; }",
+  "namespace ns { void foo(); void foo() {}; }",
   "using namespace ns;",
   },
   {
@@ -88,8 +95,8 @@
   },
   // Redecls
   {
-  "class ^X; class ^X{}; class ^X;",
-  "X *y;",
+  "void ^foo(); void ^foo() {} void ^foo();",
+  "void bar() { foo(); }",
   },
   // Constructor
   {
Index: clang-tools-extra/clangd/IncludeCleaner.cpp
===
--- clang-tools-extra/clangd/IncludeCleaner.cpp
+++ clang-tools-extra/clangd/IncludeCleaner.cpp
@@ -122,16 +122,20 @@
   void add(const Decl *D) {
 if (!D || !isNew(D->getCanonicalDecl()))
   return;
-// If we see a declaration in the mainfile, skip all non-definition decls.
-// We only do this for classes because forward declarations are common and
-// we don't want to include every header that forward-declares the symbol
-// because they're often unrelated.
+// Special case RecordDecls, as it is common for them to be forward
+// declared multiple times. The most common cases are:
+// - Definition available in TU, only mark that one as usage. The rest is
+//   likely to be unnecessary. This might result in false positives when an
+//   internal definition is visible.
+// - There's a forward declaration in the main file, no need for other
+//   redecls.
 if (const auto *RD = llvm::dyn_cast(D)) {
-  if (SM.isInMainFile(RD->getMostRecentDecl()->getBeginLoc())) {
-if (const auto *Definition = RD->getMostRecentDecl()->getDefinition())
-  Result.insert(Definition->getLocation());
+  if (const auto *Definition = RD->getDefinition()) {
+Result.insert(Definition->getLocation());
 return;
   }
+  if (SM.isInMainFile(RD->getMostRecentDecl()->getLocation()))
+return;
 }
 for (const Decl *Redecl : D->redecls())
   Result.insert(Redecl->getLocation());


Index: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
===
--- clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -39,10 +39,10 @@
   "class ^X;",
   "X *y;",
   },
-  // FIXME(kirillbobyrev): When definition is available, we don't need to
-  // mark forward declarations as used.
+  // When definition is available, we don't need to mark forward
+  // declarations as used.
   {
-  "class ^X {}; class ^X;",
+  "class ^X {}; class X;",
   "X *y;",
   },
   // We already have forward declaration in the main file, the other
@@ -51,17 +51,24 @@
   "class ^X {}; class X;",
   "class X; X *y;",
   },
+  // Nested class definition can occur outside of the parent class
+  // definition. Bar declaration should be visible to its definition but
+  // it will always be because we will mark Foo definition as used.
+  {
+  "class ^Foo { class Bar; 

[clang-tools-extra] bab7a30 - [clangd] IncludeCleaner: Do not require forward declarations of RecordDecls when definition is available

2021-12-03 Thread Kirill Bobyrev via cfe-commits

Author: Kirill Bobyrev
Date: 2021-12-03T09:36:50+01:00
New Revision: bab7a30ab692059e5e9dc867a59b9ead47efd35c

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

LOG: [clangd] IncludeCleaner: Do not require forward declarations of 
RecordDecls when definition is available

This makes IncludeCleaner more useful in the presense of a large number of
forward declarations. If the definition is already in the Translation Unit and
visible to the Main File, forward declarations have no effect.

The original patch D112707 was split in two: D114864 and this one.

Reviewed By: kadircet

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

Added: 


Modified: 
clang-tools-extra/clangd/IncludeCleaner.cpp
clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/IncludeCleaner.cpp 
b/clang-tools-extra/clangd/IncludeCleaner.cpp
index 76d5d626b9f88..0e44c080625af 100644
--- a/clang-tools-extra/clangd/IncludeCleaner.cpp
+++ b/clang-tools-extra/clangd/IncludeCleaner.cpp
@@ -122,16 +122,20 @@ class ReferencedLocationCrawler
   void add(const Decl *D) {
 if (!D || !isNew(D->getCanonicalDecl()))
   return;
-// If we see a declaration in the mainfile, skip all non-definition decls.
-// We only do this for classes because forward declarations are common and
-// we don't want to include every header that forward-declares the symbol
-// because they're often unrelated.
+// Special case RecordDecls, as it is common for them to be forward
+// declared multiple times. The most common cases are:
+// - Definition available in TU, only mark that one as usage. The rest is
+//   likely to be unnecessary. This might result in false positives when an
+//   internal definition is visible.
+// - There's a forward declaration in the main file, no need for other
+//   redecls.
 if (const auto *RD = llvm::dyn_cast(D)) {
-  if (SM.isInMainFile(RD->getMostRecentDecl()->getBeginLoc())) {
-if (const auto *Definition = RD->getMostRecentDecl()->getDefinition())
-  Result.insert(Definition->getLocation());
+  if (const auto *Definition = RD->getDefinition()) {
+Result.insert(Definition->getLocation());
 return;
   }
+  if (SM.isInMainFile(RD->getMostRecentDecl()->getLocation()))
+return;
 }
 for (const Decl *Redecl : D->redecls())
   Result.insert(Redecl->getLocation());

diff  --git a/clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp 
b/clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
index ddc0a99d58356..1313485f481df 100644
--- a/clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ b/clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -39,10 +39,10 @@ TEST(IncludeCleaner, ReferencedLocations) {
   "class ^X;",
   "X *y;",
   },
-  // FIXME(kirillbobyrev): When definition is available, we don't need to
-  // mark forward declarations as used.
+  // When definition is available, we don't need to mark forward
+  // declarations as used.
   {
-  "class ^X {}; class ^X;",
+  "class ^X {}; class X;",
   "X *y;",
   },
   // We already have forward declaration in the main file, the other
@@ -51,17 +51,24 @@ TEST(IncludeCleaner, ReferencedLocations) {
   "class ^X {}; class X;",
   "class X; X *y;",
   },
+  // Nested class definition can occur outside of the parent class
+  // definition. Bar declaration should be visible to its definition but
+  // it will always be because we will mark Foo definition as used.
+  {
+  "class ^Foo { class Bar; };",
+  "class Foo::Bar {};",
+  },
   // TypedefType and UsingDecls
   {
   "using ^Integer = int;",
   "Integer x;",
   },
   {
-  "namespace ns { struct ^X; struct ^X {}; }",
-  "using ns::X;",
+  "namespace ns { void ^foo(); void ^foo() {} }",
+  "using ns::foo;",
   },
   {
-  "namespace ns { struct X; struct X {}; }",
+  "namespace ns { void foo(); void foo() {}; }",
   "using namespace ns;",
   },
   {
@@ -88,8 +95,8 @@ TEST(IncludeCleaner, ReferencedLocations) {
   },
   // Redecls
   {
-  "class ^X; class ^X{}; class ^X;",
-  "X *y;",
+  "void ^foo(); void ^foo() {} void ^foo();",
+  "void bar() { foo(); }",
   },
   // Constructor
   {



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


[PATCH] D114949: [clangd] IncludeCleaner: Do not require forward declarations of RecordDecls when definition is available

2021-12-03 Thread Kirill Bobyrev 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 rGbab7a30ab692: [clangd] IncludeCleaner: Do not require 
forward declarations of RecordDecls… (authored by kbobyrev).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114949

Files:
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp


Index: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
===
--- clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -39,10 +39,10 @@
   "class ^X;",
   "X *y;",
   },
-  // FIXME(kirillbobyrev): When definition is available, we don't need to
-  // mark forward declarations as used.
+  // When definition is available, we don't need to mark forward
+  // declarations as used.
   {
-  "class ^X {}; class ^X;",
+  "class ^X {}; class X;",
   "X *y;",
   },
   // We already have forward declaration in the main file, the other
@@ -51,17 +51,24 @@
   "class ^X {}; class X;",
   "class X; X *y;",
   },
+  // Nested class definition can occur outside of the parent class
+  // definition. Bar declaration should be visible to its definition but
+  // it will always be because we will mark Foo definition as used.
+  {
+  "class ^Foo { class Bar; };",
+  "class Foo::Bar {};",
+  },
   // TypedefType and UsingDecls
   {
   "using ^Integer = int;",
   "Integer x;",
   },
   {
-  "namespace ns { struct ^X; struct ^X {}; }",
-  "using ns::X;",
+  "namespace ns { void ^foo(); void ^foo() {} }",
+  "using ns::foo;",
   },
   {
-  "namespace ns { struct X; struct X {}; }",
+  "namespace ns { void foo(); void foo() {}; }",
   "using namespace ns;",
   },
   {
@@ -88,8 +95,8 @@
   },
   // Redecls
   {
-  "class ^X; class ^X{}; class ^X;",
-  "X *y;",
+  "void ^foo(); void ^foo() {} void ^foo();",
+  "void bar() { foo(); }",
   },
   // Constructor
   {
Index: clang-tools-extra/clangd/IncludeCleaner.cpp
===
--- clang-tools-extra/clangd/IncludeCleaner.cpp
+++ clang-tools-extra/clangd/IncludeCleaner.cpp
@@ -122,16 +122,20 @@
   void add(const Decl *D) {
 if (!D || !isNew(D->getCanonicalDecl()))
   return;
-// If we see a declaration in the mainfile, skip all non-definition decls.
-// We only do this for classes because forward declarations are common and
-// we don't want to include every header that forward-declares the symbol
-// because they're often unrelated.
+// Special case RecordDecls, as it is common for them to be forward
+// declared multiple times. The most common cases are:
+// - Definition available in TU, only mark that one as usage. The rest is
+//   likely to be unnecessary. This might result in false positives when an
+//   internal definition is visible.
+// - There's a forward declaration in the main file, no need for other
+//   redecls.
 if (const auto *RD = llvm::dyn_cast(D)) {
-  if (SM.isInMainFile(RD->getMostRecentDecl()->getBeginLoc())) {
-if (const auto *Definition = RD->getMostRecentDecl()->getDefinition())
-  Result.insert(Definition->getLocation());
+  if (const auto *Definition = RD->getDefinition()) {
+Result.insert(Definition->getLocation());
 return;
   }
+  if (SM.isInMainFile(RD->getMostRecentDecl()->getLocation()))
+return;
 }
 for (const Decl *Redecl : D->redecls())
   Result.insert(Redecl->getLocation());


Index: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
===
--- clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -39,10 +39,10 @@
   "class ^X;",
   "X *y;",
   },
-  // FIXME(kirillbobyrev): When definition is available, we don't need to
-  // mark forward declarations as used.
+  // When definition is available, we don't need to mark forward
+  // declarations as used.
   {
-  "class ^X {}; class ^X;",
+  "class ^X {}; class X;",
   "X *y;",
   },
   // We already have forward declaration in the main file, the other
@@ -51,17 +51,24 @@
   "class ^X {}; class X;",
   "class X; X *y;",
   },
+  // Nested class definition can occur outside of the parent class
+  // definition. Bar declaration should be visible to its def

[PATCH] D113753: [Analyzer][Core] Better simplification in SimpleSValBuilder::evalBinOpNN

2021-12-03 Thread Gabor Marton via Phabricator via cfe-commits
martong added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp:372
   QualType resultTy)  {
   NonLoc InputLHS = lhs;
   NonLoc InputRHS = rhs;

steakhal wrote:
> @martong, you simplified the operands, but you overwrite only the lhs and 
> rhs. Shouldnt you overwite these as well?
> What is the purpose of these variables, do you know?
> @martong, you simplified the operands, but you overwrite only the lhs and 
> rhs. Shouldnt you overwite these as well?
> What is the purpose of these variables, do you know?

They are used exclusively to create `SymExpr`s with `makeSymExprValNN` when 
both lhs and rhs are symbols. If we were to simplify the `Input` variables then 
it might happen that we end up with a non symbol (i.e. a concrete int) and then 
`makeSymExprValNN` would fail miserably (would assert I guess). 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113753

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


[PATCH] D114968: [clang][deps] Avoid reading file for stat calls

2021-12-03 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 abandoned this revision.
jansvoboda11 added a comment.

Thanks for confirming!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114968

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


[PATCH] D114938: [Analyzer] SValBuilder: Simlify a SymExpr to the absolute simplest form

2021-12-03 Thread Gabor Marton via Phabricator via cfe-commits
martong added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp:51
+  // sub-trees and if a value is a constant we do the constant folding.
+  SVal simplifySValImpl(ProgramStateRef State, SVal V);
+

steakhal wrote:
> What about calling this `simplifySValOnce()`
Sounds better!



Comment at: clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp:1137
+  SVal SimplifiedVal = simplifySValImpl(State, Val);
+  // Do the simplification until we can.
+  while (SimplifiedVal != Val) {

steakhal wrote:
> You can remove this comment. Not really useful anyway.
Ok.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114938

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


[PATCH] D114688: [Clang] Add __builtin_elementwise_ceil

2021-12-03 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 391574.
junaire added a comment.

No more lambdas


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

https://reviews.llvm.org/D114688

Files:
  clang/include/clang/Basic/Builtins.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/builtins-elementwise-math.c
  clang/test/Sema/builtins-elementwise-math.c
  clang/test/SemaCXX/builtins-elementwise-math.cpp

Index: clang/test/SemaCXX/builtins-elementwise-math.cpp
===
--- clang/test/SemaCXX/builtins-elementwise-math.cpp
+++ clang/test/SemaCXX/builtins-elementwise-math.cpp
@@ -36,3 +36,10 @@
   static_assert(!is_const::value);
   static_assert(!is_const::value);
 }
+
+void test_builtin_elementwise_ceil() {
+  const float a = 42.0;
+  float b = 42.3;
+  static_assert(!is_const::value);
+  static_assert(!is_const::value);
+}
Index: clang/test/Sema/builtins-elementwise-math.c
===
--- clang/test/Sema/builtins-elementwise-math.c
+++ clang/test/Sema/builtins-elementwise-math.c
@@ -135,3 +135,24 @@
   c1 = __builtin_elementwise_min(c1, c2);
   // expected-error@-1 {{1st argument must be a vector, integer or floating point type (was '_Complex float')}}
 }
+
+void test_builtin_elementwise_ceil(int i, float f, double d, float4 v, int3 iv, unsigned u, unsigned4 uv) {
+
+  struct Foo s = __builtin_elementwise_ceil(f);
+  // expected-error@-1 {{initializing 'struct Foo' with an expression of incompatible type 'float'}}
+
+  i = __builtin_elementwise_ceil();
+  // expected-error@-1 {{too few arguments to function call, expected 1, have 0}}
+
+  i = __builtin_elementwise_ceil(i);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'int')}}
+
+  i = __builtin_elementwise_ceil(f, f);
+  // expected-error@-1 {{too many arguments to function call, expected 1, have 2}}
+
+  u = __builtin_elementwise_ceil(u);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'unsigned int')}}
+
+  uv = __builtin_elementwise_ceil(uv);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'unsigned4' (vector of 4 'unsigned int' values))}}
+}
Index: clang/test/CodeGen/builtins-elementwise-math.c
===
--- clang/test/CodeGen/builtins-elementwise-math.c
+++ clang/test/CodeGen/builtins-elementwise-math.c
@@ -189,3 +189,20 @@
   // CHECK-NEXT: call i32 @llvm.smin.i32(i32 [[IAS1]], i32 [[B]])
   int_as_one = __builtin_elementwise_min(int_as_one, b);
 }
+
+void test_builtin_elementwise_ceil(float f1, float f2, double d1, double d2,
+   float4 vf1, float4 vf2, si8 vi1, si8 vi2,
+   long long int i1, long long int i2, short si) {
+  // CHECK-LABEL: define void @test_builtin_elementwise_ceil(
+  // CHECK:  [[F1:%.+]] = load float, float* %f1.addr, align 4
+  // CHECK-NEXT:  call float @llvm.ceil.f32(float [[F1]])
+  f2 = __builtin_elementwise_ceil(f1);
+
+  // CHECK:  [[D1:%.+]] = load double, double* %d1.addr, align 8
+  // CHECK-NEXT: call double @llvm.ceil.f64(double [[D1]])
+  d2 = __builtin_elementwise_ceil(d1);
+
+  // CHECK:  [[VF1:%.+]] = load <4 x float>, <4 x float>* %vf1.addr, align 16
+  // CHECK-NEXT: call <4 x float> @llvm.ceil.v4f32(<4 x float> [[VF1]])
+  vf2 = __builtin_elementwise_ceil(vf1);
+}
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -2098,10 +2098,47 @@
 break;
   }
 
-  case Builtin::BI__builtin_elementwise_abs:
-if (SemaBuiltinElementwiseMathOneArg(TheCall))
+  // __builtin_elementwise_abs estricts the element type to signed integers or
+  // floating point types only.
+  case Builtin::BI__builtin_elementwise_abs: {
+if (PrepareBuiltinElementwiseMathOneArgCall(TheCall))
   return ExprError();
+
+QualType ArgTy = TheCall->getArg(0)->getType();
+QualType EltTy = ArgTy;
+
+if (auto *VecTy = EltTy->getAs())
+  EltTy = VecTy->getElementType();
+if (EltTy->isUnsignedIntegerType()) {
+  Diag(TheCall->getArg(0)->getBeginLoc(),
+   diag::err_builtin_invalid_arg_type)
+  << 1 << /* signed integer or float ty*/ 3 << ArgTy;
+  return ExprError();
+}
+break;
+  }
+
+  // __builtin_elementwise_abs estricts the element type to floating point
+  // types only.
+  case Builtin::BI__builtin_elementwise_ceil: {
+if (PrepareBuiltinElementwiseMathOneArgCall(TheCall))
+  return ExprError();
+
+QualType ArgTy = TheCall->getArg(0)->getType();
+QualType EltTy = ArgTy;
+
+if (auto *VecTy = EltTy->getAs())
+  EltTy = VecTy->getElementType();
+if (!EltTy->isFloatingType()) {
+

[PATCH] D115031: [AST] Print NTTP args as string-literals when possible

2021-12-03 Thread Zhihao Yuan via Phabricator via cfe-commits
lichray created this revision.
lichray requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

C++20 NTTP (non-type template parameter) prints `MyType<{{116, 104, 105, 
115}}>` when the code is as simple as `MyType<"this">`. Of course, due to the 
need for an intermediate structural type to trigger CTAD, it'd be better to 
keep one layer of the braces. So this patch prints `MyType<{"this"}>`.

Currently, `StringLiteral` can handle this case nicely, but `StringLiteral` 
inside `APValue` code looks like a circular dependency. So, in this patch, I 
implemented a very cheap strategy to emit string literals in diagnostic message 
only when it's more readable and fall back to integer sequences. *Please tell 
me whether this approach is acceptable* before I write tests.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D115031

Files:
  clang/lib/AST/APValue.cpp

Index: clang/lib/AST/APValue.cpp
===
--- clang/lib/AST/APValue.cpp
+++ clang/lib/AST/APValue.cpp
@@ -625,6 +625,97 @@
   return V.convertToDouble();
 }
 
+static bool TryPrintAsStringLiteral(raw_ostream &Out, const ArrayType *ATy,
+const APValue *Data, size_t Size) {
+  if (Size == 0)
+return false;
+
+  QualType Ty = ATy->getElementType();
+  if (!Ty->isAnyCharacterType())
+return false;
+
+  // Nothing we can do about a sequence that is not null-terminated
+  if (!Data[--Size].getInt().isZero())
+return false;
+
+  constexpr size_t MaxN = 36;
+  char Buf[MaxN * 2 + 3] = {'"'}; // "At most 36 escaped chars" + \0
+  auto *pBuf = Buf + 1;
+
+  // Better than printing a two-digit sequence of 10 integers.
+  StringRef Ellipsis;
+  if (Size > MaxN) {
+Ellipsis = " [...]";
+Size = std::min(MaxN - Ellipsis.size(), Size);
+  }
+
+  auto writeEscape = [](char *Ptr, char Ch) {
+Ptr[0] = '\\';
+Ptr[1] = Ch;
+return Ptr + 2;
+  };
+
+  for (auto &Val : ArrayRef(Data, Size)) {
+auto Char64 = Val.getInt().getExtValue();
+if (Char64 > 0x7f)
+  return false; // Bye bye, see you in integers.
+switch (auto Ch = static_cast(Char64)) {
+default:
+  if (isPrintable(Ch)) {
+*pBuf++ = Ch;
+break;
+  }
+  return false;
+case '\\':
+case '\'': // The diagnostic message is 'quoted'
+  pBuf = writeEscape(pBuf, Ch);
+  break;
+case '\0':
+  pBuf = writeEscape(pBuf, '0');
+  break;
+case '\a':
+  pBuf = writeEscape(pBuf, 'a');
+  break;
+case '\b':
+  pBuf = writeEscape(pBuf, 'b');
+  break;
+case '\f':
+  pBuf = writeEscape(pBuf, 'f');
+  break;
+case '\n':
+  pBuf = writeEscape(pBuf, 'n');
+  break;
+case '\r':
+  pBuf = writeEscape(pBuf, 'r');
+  break;
+case '\t':
+  pBuf = writeEscape(pBuf, 't');
+  break;
+case '\v':
+  pBuf = writeEscape(pBuf, 'v');
+  break;
+}
+  }
+
+  if (!Ellipsis.empty()) {
+memcpy(pBuf, Ellipsis.data(), Ellipsis.size());
+pBuf += Ellipsis.size();
+  }
+  *pBuf++ = '"';
+
+  if (Ty->isWideCharType())
+Out << 'L';
+  else if (Ty->isChar8Type())
+Out << "u8";
+  else if (Ty->isChar16Type())
+Out << 'u';
+  else if (Ty->isChar32Type())
+Out << 'U';
+
+  Out << StringRef(Buf, pBuf - Buf);
+  return true;
+}
+
 void APValue::printPretty(raw_ostream &Out, const ASTContext &Ctx,
   QualType Ty) const {
   printPretty(Out, Ctx.getPrintingPolicy(), Ty, &Ctx);
@@ -795,17 +886,22 @@
   }
   case APValue::Array: {
 const ArrayType *AT = Ty->castAsArrayTypeUnsafe();
+if (TryPrintAsStringLiteral(Out, AT, &getArrayInitializedElt(0),
+getArrayInitializedElts()))
+  return;
 QualType ElemTy = AT->getElementType();
 Out << '{';
-if (unsigned N = getArrayInitializedElts()) {
-  getArrayInitializedElt(0).printPretty(Out, Policy, ElemTy, Ctx);
-  for (unsigned I = 1; I != N; ++I) {
+unsigned I = 0;
+switch (unsigned N = getArrayInitializedElts()) {
+case 0:
+  for (; I != N; ++I) {
 Out << ", ";
 if (I == 10) {
-  // Avoid printing out the entire contents of large arrays.
-  Out << "...";
-  break;
+  Out << "...}";
+  return;
 }
+LLVM_FALLTHROUGH;
+  default:
 getArrayInitializedElt(I).printPretty(Out, Policy, ElemTy, Ctx);
   }
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D114116: [clang][ARM] relax -mtp=cp15 for non-thumb cases

2021-12-03 Thread Peter Smith via Phabricator via cfe-commits
peter.smith accepted this revision.
peter.smith added a comment.
This revision is now accepted and ready to land.

LGTM, thanks for the update.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114116

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


[PATCH] D113753: [Analyzer][Core] Better simplification in SimpleSValBuilder::evalBinOpNN

2021-12-03 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp:372
   QualType resultTy)  {
   NonLoc InputLHS = lhs;
   NonLoc InputRHS = rhs;

martong wrote:
> steakhal wrote:
> > @martong, you simplified the operands, but you overwrite only the lhs and 
> > rhs. Shouldnt you overwite these as well?
> > What is the purpose of these variables, do you know?
> > @martong, you simplified the operands, but you overwrite only the lhs and 
> > rhs. Shouldnt you overwite these as well?
> > What is the purpose of these variables, do you know?
> 
> They are used exclusively to create `SymExpr`s with `makeSymExprValNN` when 
> both lhs and rhs are symbols. If we were to simplify the `Input` variables 
> then it might happen that we end up with a non symbol (i.e. a concrete int) 
> and then `makeSymExprValNN` would fail miserably (would assert I guess). 
I see. Although, it still seems suboptimal.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113753

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


[clang] 4f94c02 - [Clang] Mutate bulitin names under IEEE128 on PPC64

2021-12-03 Thread Qiu Chaofan via cfe-commits

Author: Qiu Chaofan
Date: 2021-12-03T17:50:18+08:00
New Revision: 4f94c02616025ace168899b6fbdc8c3ba240062b

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

LOG: [Clang] Mutate bulitin names under IEEE128 on PPC64

Glibc 2.32 and newer uses these symbol names to support IEEE-754 128-bit
float. GCC transforms name of these builtins to align with Glibc header
behavior.

Since Clang doesn't have all GCC-compatible builtins implemented, this
patch only mutates the implemented part.

Note nexttoward is a special case (no nexttowardf128) so it's also
handled here.

Reviewed By: jsji

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

Added: 
clang/test/CodeGen/ppc64-f128-builtins.c

Modified: 
clang/lib/CodeGen/CGBuiltin.cpp
clang/test/CodeGen/math-builtins-long.c

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 5d6df59cc405..0a98b5b63322 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -96,13 +96,33 @@ llvm::Constant *CodeGenModule::getBuiltinLibFunction(const 
FunctionDecl *FD,
   StringRef Name;
   GlobalDecl D(FD);
 
+  // TODO: This list should be expanded or refactored after all GCC-compatible
+  // std libcall builtins are implemented.
+  static SmallDenseMap F128Builtins{
+  {Builtin::BI__builtin_printf, "__printfieee128"},
+  {Builtin::BI__builtin_vsnprintf, "__vsnprintfieee128"},
+  {Builtin::BI__builtin_vsprintf, "__vsprintfieee128"},
+  {Builtin::BI__builtin_sprintf, "__sprintfieee128"},
+  {Builtin::BI__builtin_snprintf, "__snprintfieee128"},
+  {Builtin::BI__builtin_fprintf, "__fprintfieee128"},
+  {Builtin::BI__builtin_nexttowardf128, "__nexttowardieee128"},
+  };
+
   // If the builtin has been declared explicitly with an assembler label,
   // use the mangled name. This 
diff ers from the plain label on platforms
   // that prefix labels.
   if (FD->hasAttr())
 Name = getMangledName(D);
-  else
-Name = Context.BuiltinInfo.getName(BuiltinID) + 10;
+  else {
+// TODO: This mutation should also be applied to other targets other than
+// PPC, after backend supports IEEE 128-bit style libcalls.
+if (getTriple().isPPC64() &&
+&getTarget().getLongDoubleFormat() == &llvm::APFloat::IEEEquad() &&
+F128Builtins.find(BuiltinID) != F128Builtins.end())
+  Name = F128Builtins[BuiltinID];
+else
+  Name = Context.BuiltinInfo.getName(BuiltinID) + 10;
+  }
 
   llvm::FunctionType *Ty =
 cast(getTypes().ConvertType(FD->getType()));

diff  --git a/clang/test/CodeGen/math-builtins-long.c 
b/clang/test/CodeGen/math-builtins-long.c
index f5cee75acad6..dfca1ed8927c 100644
--- a/clang/test/CodeGen/math-builtins-long.c
+++ b/clang/test/CodeGen/math-builtins-long.c
@@ -307,7 +307,7 @@ void foo(long double f, long double *l, int *i, const char 
*c) {
   // F80: call x86_fp80 @nexttowardl(x86_fp80 %{{.+}}, x86_fp80 %{{.+}})
   // PPC: call ppc_fp128 @nexttowardl(ppc_fp128 %{{.+}}, ppc_fp128 %{{.+}})
   // X86F128: call fp128 @nexttowardl(fp128 %{{.+}}, fp128 %{{.+}})
-  // PPCF128: call fp128 @nexttowardf128(fp128 %{{.+}}, fp128 %{{.+}})
+  // PPCF128: call fp128 @__nexttowardieee128(fp128 %{{.+}}, fp128 %{{.+}})
   __builtin_nexttowardl(f,f);
 
   // F80: call x86_fp80 @remainderl(x86_fp80 %{{.+}}, x86_fp80 %{{.+}})

diff  --git a/clang/test/CodeGen/ppc64-f128-builtins.c 
b/clang/test/CodeGen/ppc64-f128-builtins.c
new file mode 100644
index ..07d1564127b2
--- /dev/null
+++ b/clang/test/CodeGen/ppc64-f128-builtins.c
@@ -0,0 +1,63 @@
+// RUN: %clang_cc1 -triple powerpc64le-linux-gnu -emit-llvm -o - %s \
+// RUN:   -mabi=ieeelongdouble | FileCheck --check-prefix=IEEE128 %s
+// RUN: %clang_cc1 -triple powerpc64le-linux-gnu -emit-llvm -o - %s \
+// RUN:   | FileCheck --check-prefix=PPC128 %s
+
+long double x;
+char buf[20];
+
+// IEEE128-LABEL: define dso_local void @test_printf
+// IEEE128: call signext i32 (i8*, ...) @__printfieee128
+// PPC128-LABEL: define dso_local void @test_printf
+// PPC128: call signext i32 (i8*, ...) @printf
+void test_printf() {
+  __builtin_printf("%.Lf", x);
+}
+
+// IEEE128-LABEL: define dso_local void @test_vsnprintf
+// IEEE128: call signext i32 @__vsnprintfieee128
+// PPC128-LABEL: define dso_local void @test_vsnprintf
+// PPC128: call signext i32 @vsnprintf
+void test_vsnprintf(int n, ...) {
+  __builtin_va_list va;
+  __builtin_va_start(va, n);
+  __builtin_vsnprintf(buf, 20, "%.Lf", va);
+  __builtin_va_end(va);
+}
+
+// IEEE128-LABEL: define dso_local void @test_vsprintf
+// IEEE128: call signext i32 @__vsprintfieee128
+// PPC128-LABEL: define dso_local void @test_vsprintf
+// PPC128: call signext i32 @vsprintf
+void test_vsprintf(int n, ...) {
+  __builtin_va_list va;
+  __b

[PATCH] D112401: [Clang] Mutate printf bulitin names under IEEE128 on PPC64

2021-12-03 Thread Qiu Chaofan 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 rG4f94c0261602: [Clang] Mutate bulitin names under IEEE128 on 
PPC64 (authored by qiucf).

Changed prior to commit:
  https://reviews.llvm.org/D112401?vs=383715&id=391582#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112401

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/math-builtins-long.c
  clang/test/CodeGen/ppc64-f128-builtins.c

Index: clang/test/CodeGen/ppc64-f128-builtins.c
===
--- /dev/null
+++ clang/test/CodeGen/ppc64-f128-builtins.c
@@ -0,0 +1,63 @@
+// RUN: %clang_cc1 -triple powerpc64le-linux-gnu -emit-llvm -o - %s \
+// RUN:   -mabi=ieeelongdouble | FileCheck --check-prefix=IEEE128 %s
+// RUN: %clang_cc1 -triple powerpc64le-linux-gnu -emit-llvm -o - %s \
+// RUN:   | FileCheck --check-prefix=PPC128 %s
+
+long double x;
+char buf[20];
+
+// IEEE128-LABEL: define dso_local void @test_printf
+// IEEE128: call signext i32 (i8*, ...) @__printfieee128
+// PPC128-LABEL: define dso_local void @test_printf
+// PPC128: call signext i32 (i8*, ...) @printf
+void test_printf() {
+  __builtin_printf("%.Lf", x);
+}
+
+// IEEE128-LABEL: define dso_local void @test_vsnprintf
+// IEEE128: call signext i32 @__vsnprintfieee128
+// PPC128-LABEL: define dso_local void @test_vsnprintf
+// PPC128: call signext i32 @vsnprintf
+void test_vsnprintf(int n, ...) {
+  __builtin_va_list va;
+  __builtin_va_start(va, n);
+  __builtin_vsnprintf(buf, 20, "%.Lf", va);
+  __builtin_va_end(va);
+}
+
+// IEEE128-LABEL: define dso_local void @test_vsprintf
+// IEEE128: call signext i32 @__vsprintfieee128
+// PPC128-LABEL: define dso_local void @test_vsprintf
+// PPC128: call signext i32 @vsprintf
+void test_vsprintf(int n, ...) {
+  __builtin_va_list va;
+  __builtin_va_start(va, n);
+  __builtin_vsprintf(buf, "%.Lf", va);
+  __builtin_va_end(va);
+}
+
+// IEEE128-LABEL: define dso_local void @test_sprintf
+// IEEE128: call signext i32 (i8*, i8*, ...) @__sprintfieee128
+// PPC128-LABEL: define dso_local void @test_sprintf
+// PPC128: call signext i32 (i8*, i8*, ...) @sprintf
+void test_sprintf() {
+  __builtin_sprintf(buf, "%.Lf", x);
+}
+
+// IEEE128-LABEL: define dso_local void @test_snprintf
+// IEEE128: call signext i32 (i8*, i64, i8*, ...) @__snprintfieee128
+// PPC128-LABEL: define dso_local void @test_snprintf
+// PPC128: call signext i32 (i8*, i64, i8*, ...) @snprintf
+void test_snprintf() {
+  __builtin_snprintf(buf, 20, "%.Lf", x);
+}
+
+// GLIBC has special handling of 'nexttoward'
+
+// IEEE128-LABEL: define dso_local fp128 @test_nexttoward
+// IEEE128: call fp128 @__nexttowardieee128
+// PPC128-LABEL: define dso_local ppc_fp128 @test_nexttoward
+// PPC128: call ppc_fp128 @nexttowardl
+long double test_nexttoward(long double a, long double b) {
+  return __builtin_nexttowardl(a, b);
+}
Index: clang/test/CodeGen/math-builtins-long.c
===
--- clang/test/CodeGen/math-builtins-long.c
+++ clang/test/CodeGen/math-builtins-long.c
@@ -307,7 +307,7 @@
   // F80: call x86_fp80 @nexttowardl(x86_fp80 %{{.+}}, x86_fp80 %{{.+}})
   // PPC: call ppc_fp128 @nexttowardl(ppc_fp128 %{{.+}}, ppc_fp128 %{{.+}})
   // X86F128: call fp128 @nexttowardl(fp128 %{{.+}}, fp128 %{{.+}})
-  // PPCF128: call fp128 @nexttowardf128(fp128 %{{.+}}, fp128 %{{.+}})
+  // PPCF128: call fp128 @__nexttowardieee128(fp128 %{{.+}}, fp128 %{{.+}})
   __builtin_nexttowardl(f,f);
 
   // F80: call x86_fp80 @remainderl(x86_fp80 %{{.+}}, x86_fp80 %{{.+}})
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -96,13 +96,33 @@
   StringRef Name;
   GlobalDecl D(FD);
 
+  // TODO: This list should be expanded or refactored after all GCC-compatible
+  // std libcall builtins are implemented.
+  static SmallDenseMap F128Builtins{
+  {Builtin::BI__builtin_printf, "__printfieee128"},
+  {Builtin::BI__builtin_vsnprintf, "__vsnprintfieee128"},
+  {Builtin::BI__builtin_vsprintf, "__vsprintfieee128"},
+  {Builtin::BI__builtin_sprintf, "__sprintfieee128"},
+  {Builtin::BI__builtin_snprintf, "__snprintfieee128"},
+  {Builtin::BI__builtin_fprintf, "__fprintfieee128"},
+  {Builtin::BI__builtin_nexttowardf128, "__nexttowardieee128"},
+  };
+
   // If the builtin has been declared explicitly with an assembler label,
   // use the mangled name. This differs from the plain label on platforms
   // that prefix labels.
   if (FD->hasAttr())
 Name = getMangledName(D);
-  else
-Name = Context.BuiltinInfo.getName(BuiltinID) + 10;
+  else {
+// TODO: This mutation should also be applied to other targets other than
+// PPC, after backend supports IEE

[PATCH] D115032: [AMDGPU] Change llvm.amdgcn.image.bvh.intersect.ray to take vec3 args

2021-12-03 Thread Jay Foad via Phabricator via cfe-commits
foad created this revision.
foad added reviewers: arsenm, rampitec, yaxunl, critson, b-sumner.
Herald added subscribers: kerbowa, hiraditya, t-tye, Anastasia, tpr, dstuttard, 
nhaehnle, jvesely, kzhuravl.
foad requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, wdng.
Herald added projects: clang, LLVM.

The ray_origin, ray_dir and ray_inv_dir arguments should all be vec3 to
match how the hardware instruction works.

Don't change the API of the corresponding OpenCL builtins.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D115032

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGenOpenCL/builtins-amdgcn-raytracing.cl
  llvm/include/llvm/IR/IntrinsicsAMDGPU.td
  llvm/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp
  llvm/lib/Target/AMDGPU/SIISelLowering.cpp
  llvm/test/CodeGen/AMDGPU/GlobalISel/llvm.amdgcn.intersect_ray.ll
  llvm/test/CodeGen/AMDGPU/llvm.amdgcn.intersect_ray.ll

Index: llvm/test/CodeGen/AMDGPU/llvm.amdgcn.intersect_ray.ll
===
--- llvm/test/CodeGen/AMDGPU/llvm.amdgcn.intersect_ray.ll
+++ llvm/test/CodeGen/AMDGPU/llvm.amdgcn.intersect_ray.ll
@@ -3,15 +3,15 @@
 ; RUN: llc -march=amdgcn -mcpu=gfx1030 -verify-machineinstrs < %s | FileCheck -check-prefixes=GCN,GFX1030 %s
 ; RUN: not --crash llc -march=amdgcn -mcpu=gfx1012 -verify-machineinstrs < %s 2>&1 | FileCheck -check-prefix=ERR %s
 
-; uint4 llvm.amdgcn.image.bvh.intersect.ray.i32.v4f32(uint node_ptr, float ray_extent, float4 ray_origin, float4 ray_dir, float4 ray_inv_dir, uint4 texture_descr)
-; uint4 llvm.amdgcn.image.bvh.intersect.ray.i32.v4f16(uint node_ptr, float ray_extent, float4 ray_origin, half4 ray_dir, half4 ray_inv_dir, uint4 texture_descr)
-; uint4 llvm.amdgcn.image.bvh.intersect.ray.i64.v4f32(ulong node_ptr, float ray_extent, float4 ray_origin, float4 ray_dir, float4 ray_inv_dir, uint4 texture_descr)
-; uint4 llvm.amdgcn.image.bvh.intersect.ray.i64.v4f16(ulong node_ptr, float ray_extent, float4 ray_origin, half4 ray_dir, half4 ray_inv_dir, uint4 texture_descr)
+; uint4 llvm.amdgcn.image.bvh.intersect.ray.i32.v4f32(uint node_ptr, float ray_extent, float3 ray_origin, float3 ray_dir, float3 ray_inv_dir, uint4 texture_descr)
+; uint4 llvm.amdgcn.image.bvh.intersect.ray.i32.v4f16(uint node_ptr, float ray_extent, float3 ray_origin, half3 ray_dir, half3 ray_inv_dir, uint4 texture_descr)
+; uint4 llvm.amdgcn.image.bvh.intersect.ray.i64.v4f32(ulong node_ptr, float ray_extent, float3 ray_origin, float3 ray_dir, float3 ray_inv_dir, uint4 texture_descr)
+; uint4 llvm.amdgcn.image.bvh.intersect.ray.i64.v4f16(ulong node_ptr, float ray_extent, float3 ray_origin, half3 ray_dir, half3 ray_inv_dir, uint4 texture_descr)
 
-declare <4 x i32> @llvm.amdgcn.image.bvh.intersect.ray.i32.v4f32(i32, float, <4 x float>, <4 x float>, <4 x float>, <4 x i32>)
-declare <4 x i32> @llvm.amdgcn.image.bvh.intersect.ray.i32.v4f16(i32, float, <4 x float>, <4 x half>, <4 x half>, <4 x i32>)
-declare <4 x i32> @llvm.amdgcn.image.bvh.intersect.ray.i64.v4f32(i64, float, <4 x float>, <4 x float>, <4 x float>, <4 x i32>)
-declare <4 x i32> @llvm.amdgcn.image.bvh.intersect.ray.i64.v4f16(i64, float, <4 x float>, <4 x half>, <4 x half>, <4 x i32>)
+declare <4 x i32> @llvm.amdgcn.image.bvh.intersect.ray.i32.v4f32(i32, float, <3 x float>, <3 x float>, <3 x float>, <4 x i32>)
+declare <4 x i32> @llvm.amdgcn.image.bvh.intersect.ray.i32.v4f16(i32, float, <3 x float>, <3 x half>, <3 x half>, <4 x i32>)
+declare <4 x i32> @llvm.amdgcn.image.bvh.intersect.ray.i64.v4f32(i64, float, <3 x float>, <3 x float>, <3 x float>, <4 x i32>)
+declare <4 x i32> @llvm.amdgcn.image.bvh.intersect.ray.i64.v4f16(i64, float, <3 x float>, <3 x half>, <3 x half>, <4 x i32>)
 
 ; ERR: in function image_bvh_intersect_ray{{.*}}intrinsic not supported on subtarget
 ; Arguments are flattened to represent the actual VGPR_A layout, so we have no
@@ -23,43 +23,43 @@
 ; GCN-NEXT:s_waitcnt vmcnt(0)
 ; GCN-NEXT:; return to shader part epilog
 main_body:
-  %ray_origin0 = insertelement <4 x float> undef, float %ray_origin_x, i32 0
-  %ray_origin1 = insertelement <4 x float> %ray_origin0, float %ray_origin_y, i32 1
-  %ray_origin = insertelement <4 x float> %ray_origin1, float %ray_origin_z, i32 2
-  %ray_dir0 = insertelement <4 x float> undef, float %ray_dir_x, i32 0
-  %ray_dir1 = insertelement <4 x float> %ray_dir0, float %ray_dir_y, i32 1
-  %ray_dir = insertelement <4 x float> %ray_dir1, float %ray_dir_z, i32 2
-  %ray_inv_dir0 = insertelement <4 x float> undef, float %ray_inv_dir_x, i32 0
-  %ray_inv_dir1 = insertelement <4 x float> %ray_inv_dir0, float %ray_inv_dir_y, i32 1
-  %ray_inv_dir = insertelement <4 x float> %ray_inv_dir1, float %ray_inv_dir_z, i32 2
-  %v = call <4 x i32> @llvm.amdgcn.image.bvh.intersect.ray.i32.v4f32(i32 %node_ptr, float %ray_extent, <4 x float> %ray_origin, <4 x float> %ray_dir, <4 x float> %ray_inv_dir, <4 x i32> %tdescr)
+  %ray_origin0 = insertelemen

[PATCH] D115032: [AMDGPU] Change llvm.amdgcn.image.bvh.intersect.ray to take vec3 args

2021-12-03 Thread Jay Foad via Phabricator via cfe-commits
foad added a comment.

This is an alternative to D114957  that does 
not update the API of the OpenCL builtins.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115032

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


[PATCH] D114957: [AMDGPU] Change llvm.amdgcn.image.bvh.intersect.ray to take vec3 args

2021-12-03 Thread Jay Foad via Phabricator via cfe-commits
foad added a comment.

In D114957#3167700 , @arsenm wrote:

> I think this macro is purely terrible and should not be added (and at least 
> should be all caps?). If we can't just hard break users, I would rather just 
> leave the builtin signatures broken

OK, how about D115032 ?

Personally I have no opinion about what's best to do with the OpenCL builtins, 
but I would like to make progress with changing the intrinsics. So I have a 
slight preference for D115032  because it 
gives me a way forward without changing OpenCL behaviour. The OpenCL team can 
then decide whether or not to update the builtins at their leisure.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114957

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


[clang] b9adaa1 - [PowerPC] [Clang] Fix alignment adjustment of single-elemented float128

2021-12-03 Thread Qiu Chaofan via cfe-commits

Author: Qiu Chaofan
Date: 2021-12-03T18:07:34+08:00
New Revision: b9adaa1782db727df08b8138e12c1e60964885d3

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

LOG: [PowerPC] [Clang] Fix alignment adjustment of single-elemented float128

This does similar thing to 6b1341e, but fixes single element 128-bit
float type: `struct { long double x; }`.

Reviewed By: rjmccall

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

Added: 


Modified: 
clang/lib/CodeGen/TargetInfo.cpp
clang/test/CodeGen/ppc64le-varargs-f128.c

Removed: 




diff  --git a/clang/lib/CodeGen/TargetInfo.cpp 
b/clang/lib/CodeGen/TargetInfo.cpp
index 9e7e9b5248f6..3cb1f83310b6 100644
--- a/clang/lib/CodeGen/TargetInfo.cpp
+++ b/clang/lib/CodeGen/TargetInfo.cpp
@@ -5083,13 +5083,16 @@ CharUnits 
PPC64_SVR4_ABIInfo::getParamTypeAlignment(QualType Ty) const {
   if (const ComplexType *CTy = Ty->getAs())
 Ty = CTy->getElementType();
 
+  auto FloatUsesVector = [this](QualType Ty){
+return Ty->isRealFloatingType() && &getContext().getFloatTypeSemantics(
+   Ty) == &llvm::APFloat::IEEEquad();
+  };
+
   // Only vector types of size 16 bytes need alignment (larger types are
   // passed via reference, smaller types are not aligned).
   if (Ty->isVectorType()) {
 return CharUnits::fromQuantity(getContext().getTypeSize(Ty) == 128 ? 16 : 
8);
-  } else if (Ty->isRealFloatingType() &&
- &getContext().getFloatTypeSemantics(Ty) ==
- &llvm::APFloat::IEEEquad()) {
+  } else if (FloatUsesVector(Ty)) {
 // According to ABI document section 'Optional Save Areas': If extended
 // precision floating-point values in IEEE BINARY 128 QUADRUPLE PRECISION
 // format are supported, map them to a single quadword, quadword aligned.
@@ -5116,7 +5119,9 @@ CharUnits 
PPC64_SVR4_ABIInfo::getParamTypeAlignment(QualType Ty) const {
 
   // With special case aggregates, only vector base types need alignment.
   if (AlignAsType) {
-return CharUnits::fromQuantity(AlignAsType->isVectorType() ? 16 : 8);
+bool UsesVector = AlignAsType->isVectorType() ||
+  FloatUsesVector(QualType(AlignAsType, 0));
+return CharUnits::fromQuantity(UsesVector ? 16 : 8);
   }
 
   // Otherwise, we only need alignment for any aggregate type that

diff  --git a/clang/test/CodeGen/ppc64le-varargs-f128.c 
b/clang/test/CodeGen/ppc64le-varargs-f128.c
index 246e77d8a19f..81a642a5a74b 100644
--- a/clang/test/CodeGen/ppc64le-varargs-f128.c
+++ b/clang/test/CodeGen/ppc64le-varargs-f128.c
@@ -17,8 +17,11 @@
 
 #include 
 
+typedef struct { long double x; } ldbl128_s;
+
 void foo_ld(long double);
 void foo_fq(__float128);
+void foo_ls(ldbl128_s);
 
 // Verify cases when OpenMP target's and host's long-double semantics 
diff er.
 
@@ -99,3 +102,29 @@ void long_double(int n, ...) {
   foo_ld(va_arg(ap, long double));
   va_end(ap);
 }
+
+// IEEE-LABEL: define{{.*}} void @long_double_struct
+// IEEE: %[[AP1:[0-9a-zA-Z_.]+]] = bitcast i8** %[[AP:[0-9a-zA-Z_.]+]] to i8*
+// IEEE: call void @llvm.va_start(i8* %[[AP1]])
+// IEEE: %[[CUR:[0-9a-zA-Z_.]+]] = load i8*, i8** %[[AP]]
+// IEEE: %[[P0:[0-9a-zA-Z_.]+]] = ptrtoint i8* %[[CUR]] to i64
+// IEEE: %[[P1:[0-9a-zA-Z_.]+]] = add i64 %[[P0]], 15
+// IEEE: %[[P2:[0-9a-zA-Z_.]+]] = and i64 %[[P1]], -16
+// IEEE: %[[ALIGN:[0-9a-zA-Z_.]+]] = inttoptr i64 %[[P2]] to i8*
+// IEEE: %[[V0:[0-9a-zA-Z_.]+]] = getelementptr inbounds i8, i8* %[[ALIGN]], 
i64 16
+// IEEE: store i8* %[[V0]], i8** %[[AP]], align 8
+// IEEE: %[[V1:[0-9a-zA-Z_.]+]] = bitcast i8* %[[ALIGN]] to %struct.ldbl128_s*
+// IEEE: %[[V2:[0-9a-zA-Z_.]+]] = bitcast %struct.ldbl128_s* 
%[[TMP:[0-9a-zA-Z_.]+]] to i8*
+// IEEE: %[[V3:[0-9a-zA-Z_.]+]] = bitcast %struct.ldbl128_s* %[[V1]] to i8*
+// IEEE: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 16 %[[V2]], i8* align 
16 %[[V3]], i64 16, i1 false)
+// IEEE: %[[COERCE:[0-9a-zA-Z_.]+]] = getelementptr inbounds 
%struct.ldbl128_s, %struct.ldbl128_s* %[[TMP]], i32 0, i32 0
+// IEEE: %[[V4:[0-9a-zA-Z_.]+]] = load fp128, fp128* %[[COERCE]], align 16
+// IEEE: call void @foo_ls(fp128 inreg %[[V4]])
+// IEEE: %[[AP2:[0-9a-zA-Z_.]+]] = bitcast i8** %[[AP]] to i8*
+// IEEE: call void @llvm.va_end(i8* %[[AP2]])
+void long_double_struct(int n, ...) {
+  va_list ap;
+  va_start(ap, n);
+  foo_ls(va_arg(ap, ldbl128_s));
+  va_end(ap);
+}



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


[PATCH] D114937: [PowerPC] [Clang] Fix alignment adjustment of single-elemented float128

2021-12-03 Thread Qiu Chaofan 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 rGb9adaa1782db: [PowerPC] [Clang] Fix alignment adjustment of 
single-elemented float128 (authored by qiucf).

Changed prior to commit:
  https://reviews.llvm.org/D114937?vs=391254&id=391585#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114937

Files:
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/CodeGen/ppc64le-varargs-f128.c


Index: clang/test/CodeGen/ppc64le-varargs-f128.c
===
--- clang/test/CodeGen/ppc64le-varargs-f128.c
+++ clang/test/CodeGen/ppc64le-varargs-f128.c
@@ -17,8 +17,11 @@
 
 #include 
 
+typedef struct { long double x; } ldbl128_s;
+
 void foo_ld(long double);
 void foo_fq(__float128);
+void foo_ls(ldbl128_s);
 
 // Verify cases when OpenMP target's and host's long-double semantics differ.
 
@@ -99,3 +102,29 @@
   foo_ld(va_arg(ap, long double));
   va_end(ap);
 }
+
+// IEEE-LABEL: define{{.*}} void @long_double_struct
+// IEEE: %[[AP1:[0-9a-zA-Z_.]+]] = bitcast i8** %[[AP:[0-9a-zA-Z_.]+]] to i8*
+// IEEE: call void @llvm.va_start(i8* %[[AP1]])
+// IEEE: %[[CUR:[0-9a-zA-Z_.]+]] = load i8*, i8** %[[AP]]
+// IEEE: %[[P0:[0-9a-zA-Z_.]+]] = ptrtoint i8* %[[CUR]] to i64
+// IEEE: %[[P1:[0-9a-zA-Z_.]+]] = add i64 %[[P0]], 15
+// IEEE: %[[P2:[0-9a-zA-Z_.]+]] = and i64 %[[P1]], -16
+// IEEE: %[[ALIGN:[0-9a-zA-Z_.]+]] = inttoptr i64 %[[P2]] to i8*
+// IEEE: %[[V0:[0-9a-zA-Z_.]+]] = getelementptr inbounds i8, i8* %[[ALIGN]], 
i64 16
+// IEEE: store i8* %[[V0]], i8** %[[AP]], align 8
+// IEEE: %[[V1:[0-9a-zA-Z_.]+]] = bitcast i8* %[[ALIGN]] to %struct.ldbl128_s*
+// IEEE: %[[V2:[0-9a-zA-Z_.]+]] = bitcast %struct.ldbl128_s* 
%[[TMP:[0-9a-zA-Z_.]+]] to i8*
+// IEEE: %[[V3:[0-9a-zA-Z_.]+]] = bitcast %struct.ldbl128_s* %[[V1]] to i8*
+// IEEE: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 16 %[[V2]], i8* align 
16 %[[V3]], i64 16, i1 false)
+// IEEE: %[[COERCE:[0-9a-zA-Z_.]+]] = getelementptr inbounds 
%struct.ldbl128_s, %struct.ldbl128_s* %[[TMP]], i32 0, i32 0
+// IEEE: %[[V4:[0-9a-zA-Z_.]+]] = load fp128, fp128* %[[COERCE]], align 16
+// IEEE: call void @foo_ls(fp128 inreg %[[V4]])
+// IEEE: %[[AP2:[0-9a-zA-Z_.]+]] = bitcast i8** %[[AP]] to i8*
+// IEEE: call void @llvm.va_end(i8* %[[AP2]])
+void long_double_struct(int n, ...) {
+  va_list ap;
+  va_start(ap, n);
+  foo_ls(va_arg(ap, ldbl128_s));
+  va_end(ap);
+}
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -5083,13 +5083,16 @@
   if (const ComplexType *CTy = Ty->getAs())
 Ty = CTy->getElementType();
 
+  auto FloatUsesVector = [this](QualType Ty){
+return Ty->isRealFloatingType() && &getContext().getFloatTypeSemantics(
+   Ty) == &llvm::APFloat::IEEEquad();
+  };
+
   // Only vector types of size 16 bytes need alignment (larger types are
   // passed via reference, smaller types are not aligned).
   if (Ty->isVectorType()) {
 return CharUnits::fromQuantity(getContext().getTypeSize(Ty) == 128 ? 16 : 
8);
-  } else if (Ty->isRealFloatingType() &&
- &getContext().getFloatTypeSemantics(Ty) ==
- &llvm::APFloat::IEEEquad()) {
+  } else if (FloatUsesVector(Ty)) {
 // According to ABI document section 'Optional Save Areas': If extended
 // precision floating-point values in IEEE BINARY 128 QUADRUPLE PRECISION
 // format are supported, map them to a single quadword, quadword aligned.
@@ -5116,7 +5119,9 @@
 
   // With special case aggregates, only vector base types need alignment.
   if (AlignAsType) {
-return CharUnits::fromQuantity(AlignAsType->isVectorType() ? 16 : 8);
+bool UsesVector = AlignAsType->isVectorType() ||
+  FloatUsesVector(QualType(AlignAsType, 0));
+return CharUnits::fromQuantity(UsesVector ? 16 : 8);
   }
 
   // Otherwise, we only need alignment for any aggregate type that


Index: clang/test/CodeGen/ppc64le-varargs-f128.c
===
--- clang/test/CodeGen/ppc64le-varargs-f128.c
+++ clang/test/CodeGen/ppc64le-varargs-f128.c
@@ -17,8 +17,11 @@
 
 #include 
 
+typedef struct { long double x; } ldbl128_s;
+
 void foo_ld(long double);
 void foo_fq(__float128);
+void foo_ls(ldbl128_s);
 
 // Verify cases when OpenMP target's and host's long-double semantics differ.
 
@@ -99,3 +102,29 @@
   foo_ld(va_arg(ap, long double));
   va_end(ap);
 }
+
+// IEEE-LABEL: define{{.*}} void @long_double_struct
+// IEEE: %[[AP1:[0-9a-zA-Z_.]+]] = bitcast i8** %[[AP:[0-9a-zA-Z_.]+]] to i8*
+// IEEE: call void @llvm.va_start(i8* %[[AP1]])
+// IEEE: %[[CUR:[0-9a-zA-Z_.]+]] = load i8*, i8** %[[AP]]
+// IEEE: %[[P0:[0-9a-zA-Z_.]+]] = ptrtoint i8* %[[

[PATCH] D114439: [Annotation] Allow parameter pack expansions in annotate attribute

2021-12-03 Thread Steffen Larsen via Phabricator via cfe-commits
steffenlarsen updated this revision to Diff 391588.
steffenlarsen edited the summary of this revision.

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

https://reviews.llvm.org/D114439

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/test/Parser/cxx0x-attributes.cpp
  clang/test/SemaTemplate/attributes.cpp
  clang/utils/TableGen/ClangAttrEmitter.cpp

Index: clang/utils/TableGen/ClangAttrEmitter.cpp
===
--- clang/utils/TableGen/ClangAttrEmitter.cpp
+++ clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -1164,10 +1164,12 @@
   };
 
   class VariadicExprArgument : public VariadicArgument {
+bool AllowPack = false;
+
   public:
 VariadicExprArgument(const Record &Arg, StringRef Attr)
-  : VariadicArgument(Arg, Attr, "Expr *")
-{}
+: VariadicArgument(Arg, Attr, "Expr *"),
+  AllowPack(Arg.getValueAsBit("AllowPack")) {}
 
 void writeASTVisitorTraversal(raw_ostream &OS) const override {
   OS << "  {\n";
@@ -2264,6 +2266,43 @@
   OS << "#endif // CLANG_ATTR_THIS_ISA_IDENTIFIER_ARG_LIST\n\n";
 }
 
+static void emitClangAttrNumArgs(RecordKeeper &Records, raw_ostream &OS) {
+  OS << "#if defined(CLANG_ATTR_NUM_ARGS)\n";
+  std::vector Attrs = Records.getAllDerivedDefinitions("Attr");
+  for (const auto *A : Attrs) {
+std::vector Args = A->getValueAsListOfDefs("Args");
+forEachUniqueSpelling(*A, [&](const FlattenedSpelling &S) {
+  OS << ".Case(\"" << S.name() << "\", " << Args.size() << ")\n";
+});
+  }
+  OS << "#endif // CLANG_ATTR_NUM_ARGS\n\n";
+}
+
+static bool argSupportsParmPack(const Record *Arg) {
+  return !Arg->getSuperClasses().empty() &&
+ llvm::StringSwitch(
+ Arg->getSuperClasses().back().first->getName())
+ .Case("VariadicExprArgument", true)
+ .Default(false) &&
+ Arg->getValueAsBit("AllowPack");
+}
+
+static void emitClangAttrLastArgParmPackSupport(RecordKeeper &Records,
+raw_ostream &OS) {
+  OS << "#if defined(CLANG_ATTR_LAST_ARG_PARM_PACK_SUPPORT)\n";
+  std::vector Attrs = Records.getAllDerivedDefinitions("Attr");
+  for (const auto *A : Attrs) {
+std::vector Args = A->getValueAsListOfDefs("Args");
+bool LastArgSupportsParmPack =
+!Args.empty() && argSupportsParmPack(Args.back());
+forEachUniqueSpelling(*A, [&](const FlattenedSpelling &S) {
+  OS << ".Case(\"" << S.name() << "\", " << LastArgSupportsParmPack
+ << ")\n";
+});
+  }
+  OS << "#endif // CLANG_ATTR_LAST_ARG_PARM_PACK_SUPPORT\n\n";
+}
+
 static void emitAttributes(RecordKeeper &Records, raw_ostream &OS,
bool Header) {
   std::vector Attrs = Records.getAllDerivedDefinitions("Attr");
@@ -4219,6 +4258,8 @@
   emitClangAttrIdentifierArgList(Records, OS);
   emitClangAttrVariadicIdentifierArgList(Records, OS);
   emitClangAttrThisIsaIdentifierArgList(Records, OS);
+  emitClangAttrNumArgs(Records, OS);
+  emitClangAttrLastArgParmPackSupport(Records, OS);
   emitClangAttrTypeArgList(Records, OS);
   emitClangAttrLateParsedList(Records, OS);
 }
Index: clang/test/SemaTemplate/attributes.cpp
===
--- clang/test/SemaTemplate/attributes.cpp
+++ clang/test/SemaTemplate/attributes.cpp
@@ -64,6 +64,23 @@
 template [[clang::annotate("ANNOTATE_FOO"), clang::annotate("ANNOTATE_BAR")]] void HasAnnotations();
 void UseAnnotations() { HasAnnotations(); }
 
+// CHECK:  FunctionTemplateDecl {{.*}} HasPackAnnotations
+// CHECK:AnnotateAttr {{.*}} "ANNOTATE_BAZ"
+// CHECK:  FunctionDecl {{.*}} HasPackAnnotations
+// CHECK:TemplateArgument{{.*}} pack
+// CHECK-NEXT: TemplateArgument{{.*}} integral 1
+// CHECK-NEXT: TemplateArgument{{.*}} integral 2
+// CHECK-NEXT: TemplateArgument{{.*}} integral 3
+// CHECK:AnnotateAttr {{.*}} "ANNOTATE_BAZ"
+// CHECK:  ConstantExpr {{.*}} 'int'
+// CHECK-NEXT:   value: Int 1
+// CHECK:  ConstantExpr {{.*}} 'int'
+// CHECK-NEXT:   value: Int 2
+// CHECK:  ConstantExpr {{.*}} 'int'
+// CHECK-NEXT:   value: Int 3
+template  [[clang::annotate("ANNOTATE_BAZ", Is...)]] void HasPackAnnotations();
+void UsePackAnnotations() { HasPackAnnotations<1, 2, 3>(); }
+
 namespace preferred_name {
   int x [[clang::preferred_name("frank")]]; // expected-error {{expected a type}}
   int y [[clang::preferred_name(int)]]; // expected-warning {{'preferred_name' attribute only applies to class templates}}
Index: clang/test/Parser/cxx0x-attributes.cpp
===
--- clang/test/Parser/cxx0x-attributes.cpp
+++ clang/test/Parser/cxx0x-attributes.cpp
@@ -258,8 +258,14 @@
   [[]] return;
 }
 
-template void variadic() {
-  void bar 

[PATCH] D114439: [Annotation] Allow parameter pack expansions in annotate attribute

2021-12-03 Thread Steffen Larsen via Phabricator via cfe-commits
steffenlarsen added a comment.

Thank you both for the reviews! Consensus seems to be having support for pack 
expansion at argument level for now and let more complicated logic be added 
when there is an actual need. I have applied these changes as I understood them 
and have added/adjusted the requested test cases. Please have a look and let me 
know what you think. 😄

> That's what I want to avoid. :-D I would prefer that the arguments have to 
> opt into that behavior because the alternative could get ambiguous. I'd 
> rather we do some extra work to explicitly support that situation once we 
> have a specific attribute in mind for it.

I'm okay with that! I have made the changes to only allow it in the last 
argument if it is marked as supporting pack expansion. Note that it assumes 
that there are no other variadic parameters except the last one, as suggested.

> Hmm, let's make sure we're on the same page. The situations I think we should 
> avoid are:
>
>   // Mixing variadics and packs.
>   let Args = [VariadicExprArgument<"VarArgs">, VariadicExprArgument<"Pack", 
> /*AllowPack*/1>];
>   
>   // Multiple packs.
>   let Args = [VariadicExprArgument<"FirstPack", /*AllowPack*/1>, 
> VariadicExprArgument<"SecondPack", /*AllowPack*/1>];

Oh, I see what you mean. Yeah I agree for sure. I think the only exceptions we 
currently have to this is `omp` attributes, but given that they are pragmas 
they should be nowhere close to this.


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

https://reviews.llvm.org/D114439

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


[PATCH] D115014: [clang] RFC: NFC: simplify macro tokens assignment

2021-12-03 Thread Simon Tatham via Phabricator via cfe-commits
simon_tatham added a comment.

I don't think so, I'm afraid. If you look at the definition of 
`MacroInfo::tokens_begin()` in `clang/include/clang/Lex/MacroInfo.h`, you see 
that it doesn't return a raw `Token *`: it returns a C++ iterator object.

  using tokens_iterator = SmallVectorImpl::const_iterator;
  
  tokens_iterator tokens_begin() const { return ReplacementTokens.begin(); }

So you do have to dereference the iterator to get a `Token &`, and then 
address-take that to turn it into a `Token *`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115014

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


[PATCH] D25844: [Sema][ObjC] Warn about implicitly autoreleasing indirect parameters that are captured by blocks

2021-12-03 Thread Anatoly Shcherbinin via Phabricator via cfe-commits
Cy-4AH added a comment.

Hello!

What compiler do when call doStuff:

  NSString * __strong fillMe;
  NSString * __autoreleasing autorelesingFillMe = fillMe;
  doStuff(&fillMe);
  fillMe = autoreleasingFillMe;

Why it's not making the same thing in doStuff body?
Compiler generated code for yours example should be:

  void doStuff(NSString **fillMeIn) {
  __block NSString *fillMeInResult;
  __block BOOL fillMeInResultHasChanged = NO;
  [@[@"array"] enumerateObjectsUsingBlock:
^(id obj, NSUInteger idx, BOOL* stop) {
  *stop = YES;
  fillMeInResult = [@"wow" mutableCopy];
  fillMeInResultHasChanged = YES;
}
  ];
  if (fillMeInResultHasChanged) {
*fillMeIn = fillMeInResult;
  }
  }

Instead we got this warning and had to do the same stuff in every implementation


Repository:
  rL LLVM

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

https://reviews.llvm.org/D25844

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


[PATCH] D114713: [AArch64][SVE][NEON] Add NEON-SVE-Bridge intrinsics

2021-12-03 Thread Matt Devereau via Phabricator via cfe-commits
MattDevereau updated this revision to Diff 391595.
MattDevereau added a comment.

updated SVEMAP2 types
added overloadable intrinsics
updated BUILTIN function signatures


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

https://reviews.llvm.org/D114713

Files:
  clang/include/clang/Basic/BuiltinsAArch64NeonSVEBridge.def
  clang/include/clang/Basic/BuiltinsAArch64NeonSVEBridge_cg.def
  clang/include/clang/Basic/BuiltinsSVE.def
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Headers/arm_neon_sve_bridge.h
  
clang/test/CodeGen/aarch64_neon_sve_bridge_intrinsics/acle_neon_sve_bridge_dup_neonq.c
  
clang/test/CodeGen/aarch64_neon_sve_bridge_intrinsics/acle_neon_sve_bridge_get_neonq.c
  
clang/test/CodeGen/aarch64_neon_sve_bridge_intrinsics/acle_neon_sve_bridge_set_neonq.c

Index: clang/test/CodeGen/aarch64_neon_sve_bridge_intrinsics/acle_neon_sve_bridge_set_neonq.c
===
--- /dev/null
+++ clang/test/CodeGen/aarch64_neon_sve_bridge_intrinsics/acle_neon_sve_bridge_set_neonq.c
@@ -0,0 +1,183 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// REQUIRES: aarch64-registered-target
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +neon -target-feature +sve -target-feature +bf16 -fallow-half-arguments-and-returns -S -O1 -Werror -Wall -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +neon -target-feature +sve -target-feature +bf16 -fallow-half-arguments-and-returns -S -O1 -Werror -Wall -emit-llvm -o - -x c++ %s | FileCheck %s -check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +neon -target-feature +sve -target-feature +bf16 -fallow-half-arguments-and-returns -S -O1 -Werror -Wall -o /dev/null %s
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu -target-feature +neon -target-feature +sve -target-feature +bf16 -fallow-half-arguments-and-returns -S -O1 -Werror -Wall -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu -target-feature +neon -target-feature +sve -target-feature +bf16 -fallow-half-arguments-and-returns -S -O1 -Werror -Wall -emit-llvm -o - -x c++ %s | FileCheck %s -check-prefix=CPP-CHECK
+#include 
+
+#ifdef SVE_OVERLOADED_FORMS
+// A simple used,unused... macro, long enough to represent any SVE builtin.
+#define SVE_ACLE_FUNC(A1,A2_UNUSED,A3,A4_UNUSED) A1##A3
+#else
+#define SVE_ACLE_FUNC(A1,A2,A3,A4) A1##A2##A3##A4
+#endif
+
+// CHECK-LABEL: @test_svset_neonq_s8(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = call  @llvm.experimental.vector.insert.nxv16i8.v16i8( [[S:%.*]], <16 x i8> [[N:%.*]], i64 0)
+// CHECK-NEXT:ret  [[TMP0]]
+//
+// CPP-CHECK-LABEL: @_Z19test_svset_neonq_s8u10__SVInt8_t11__Int8x16_t(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = call  @llvm.experimental.vector.insert.nxv16i8.v16i8( [[S:%.*]], <16 x i8> [[N:%.*]], i64 0)
+// CPP-CHECK-NEXT:ret  [[TMP0]]
+//
+svint8_t test_svset_neonq_s8(svint8_t s, int8x16_t n) {
+  return SVE_ACLE_FUNC(svset_neonq, _s8, , )(s, n);
+}
+
+// CHECK-LABEL: @test_svset_neonq_s16(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = call  @llvm.experimental.vector.insert.nxv8i16.v8i16( [[S:%.*]], <8 x i16> [[N:%.*]], i64 0)
+// CHECK-NEXT:ret  [[TMP0]]
+//
+// CPP-CHECK-LABEL: @_Z20test_svset_neonq_s16u11__SVInt16_t11__Int16x8_t(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = call  @llvm.experimental.vector.insert.nxv8i16.v8i16( [[S:%.*]], <8 x i16> [[N:%.*]], i64 0)
+// CPP-CHECK-NEXT:ret  [[TMP0]]
+//
+svint16_t test_svset_neonq_s16(svint16_t s, int16x8_t n) {
+  return SVE_ACLE_FUNC(svset_neonq, _s16, , )(s, n);
+}
+
+// CHECK-LABEL: @test_svset_neonq_s32(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = call  @llvm.experimental.vector.insert.nxv4i32.v4i32( [[S:%.*]], <4 x i32> [[N:%.*]], i64 0)
+// CHECK-NEXT:ret  [[TMP0]]
+//
+// CPP-CHECK-LABEL: @_Z20test_svset_neonq_s32u11__SVInt32_t11__Int32x4_t(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = call  @llvm.experimental.vector.insert.nxv4i32.v4i32( [[S:%.*]], <4 x i32> [[N:%.*]], i64 0)
+// CPP-CHECK-NEXT:ret  [[TMP0]]
+//
+svint32_t test_svset_neonq_s32(svint32_t s, int32x4_t n) {
+  return SVE_ACLE_FUNC(svset_neonq, _s32, , )(s, n);
+}
+
+// CHECK-LABEL: @test_svset_neonq_s64(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = call  @llvm.experimental.vector.insert.nxv2i64.v2i64( [[S:%.*]], <2 x i64> [[N:%.*]], i64 0)
+// CHECK-NEXT:ret  [[TMP0]]
+//
+// CPP-CHECK-LABEL: @_Z20test_svset_neonq_s64u11__SVInt64_t11__Int64x2_t(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = call  @llvm.experimental.vector.insert.nxv2i64.v2i64( [[S:%.*]], <2 x i64> [[N:%.*]], i64 0)
+// CPP-CHECK-NEXT:ret  [[TMP0]]
+//

[PATCH] D115014: [clang] RFC: NFC: simplify macro tokens assignment

2021-12-03 Thread zhouyizhou via Phabricator via cfe-commits
zhouyizhou added a comment.

In D115014#3169400 , @simon_tatham 
wrote:

> I don't think so, I'm afraid. If you look at the definition of 
> `MacroInfo::tokens_begin()` in `clang/include/clang/Lex/MacroInfo.h`, you see 
> that it doesn't return a raw `Token *`: it returns a C++ iterator object.
>
>   using tokens_iterator = SmallVectorImpl::const_iterator;
>   
>   tokens_iterator tokens_begin() const { return ReplacementTokens.begin(); }
>
> So you do have to dereference the iterator to get a `Token &`, and then 
> address-take that to turn it into a `Token *`.

Thank Simon for reviewing my patch  ;-)

In llvm/include/llvm/ADT/SmallVector.h, I found  this: using const_iterator = 
const T *;

also I use gdb to print the return type of tokens_begin()
(gdb) ptype const_iterator
type = const class clang::Token {

...
} *

So, there still remains little puzzle in my head  ;-)

Thanks again
Zhouyi


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115014

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


[PATCH] D102090: [CMake][ELF] Link libLLVM.so and libclang-cpp.so with -Bsymbolic-functions

2021-12-03 Thread Evgeniy via Phabricator via cfe-commits
ebrevnov added a comment.

While -Bsymbolic-funtions brings nice performance improvements it also changes 
symbol resolution order. That means we effectively disabled  preemption for 
functions and all references from inside libLLVM*.so will be resolved locally.  
But references to global data can still be interposed by external definitions. 
Do I understand correctly that main argument against using -Bsymbolic is 
potential issue with equality comparison of address of global? Or anything else?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102090

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


[PATCH] D115014: [clang] RFC: NFC: simplify macro tokens assignment

2021-12-03 Thread Simon Tatham via Phabricator via cfe-commits
simon_tatham added a comment.

Ah, now I see what you mean – I didn't look far enough!

I don't know this code well (in fact I'm not sure why you picked me as a 
reviewer), but off the top of my head: the question is not just whether 
`tokens_iterator` happens to be the same thing as `const Token *` //now//. It's 
whether it's guaranteed to stay that way in the future.

One of the purposes of these iterator types is that they form an opaque 
abstraction layer: the client uses the type in only the ways that are 
guaranteed to work by the iterator specification, and then the implementation 
can completely change without breaking any client.

If you make a change like this, and later `SmallVector::iterator` changes to 
some other legal implementation, or `tokens_iterator` changes to be something 
other than a `SmallVector::iterator`, then this change will have to be reverted.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115014

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


[PATCH] D115031: [AST] Print NTTP args as string-literals when possible

2021-12-03 Thread Zhihao Yuan via Phabricator via cfe-commits
lichray updated this revision to Diff 391600.
lichray added a comment.

Fix failed assertion


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115031

Files:
  clang/lib/AST/APValue.cpp

Index: clang/lib/AST/APValue.cpp
===
--- clang/lib/AST/APValue.cpp
+++ clang/lib/AST/APValue.cpp
@@ -625,6 +625,97 @@
   return V.convertToDouble();
 }
 
+static bool TryPrintAsStringLiteral(raw_ostream &Out, const ArrayType *ATy,
+const APValue *Data, size_t Size) {
+  if (Size == 0)
+return false;
+
+  QualType Ty = ATy->getElementType();
+  if (!Ty->isAnyCharacterType())
+return false;
+
+  // Nothing we can do about a sequence that is not null-terminated
+  if (!Data[--Size].getInt().isZero())
+return false;
+
+  constexpr size_t MaxN = 36;
+  char Buf[MaxN * 2 + 3] = {'"'}; // "At most 36 escaped chars" + \0
+  auto *pBuf = Buf + 1;
+
+  // Better than printing a two-digit sequence of 10 integers.
+  StringRef Ellipsis;
+  if (Size > MaxN) {
+Ellipsis = " [...]";
+Size = std::min(MaxN - Ellipsis.size(), Size);
+  }
+
+  auto writeEscape = [](char *Ptr, char Ch) {
+Ptr[0] = '\\';
+Ptr[1] = Ch;
+return Ptr + 2;
+  };
+
+  for (auto &Val : ArrayRef(Data, Size)) {
+auto Char64 = Val.getInt().getExtValue();
+if (Char64 > 0x7f)
+  return false; // Bye bye, see you in integers.
+switch (auto Ch = static_cast(Char64)) {
+default:
+  if (isPrintable(Ch)) {
+*pBuf++ = Ch;
+break;
+  }
+  return false;
+case '\\':
+case '\'': // The diagnostic message is 'quoted'
+  pBuf = writeEscape(pBuf, Ch);
+  break;
+case '\0':
+  pBuf = writeEscape(pBuf, '0');
+  break;
+case '\a':
+  pBuf = writeEscape(pBuf, 'a');
+  break;
+case '\b':
+  pBuf = writeEscape(pBuf, 'b');
+  break;
+case '\f':
+  pBuf = writeEscape(pBuf, 'f');
+  break;
+case '\n':
+  pBuf = writeEscape(pBuf, 'n');
+  break;
+case '\r':
+  pBuf = writeEscape(pBuf, 'r');
+  break;
+case '\t':
+  pBuf = writeEscape(pBuf, 't');
+  break;
+case '\v':
+  pBuf = writeEscape(pBuf, 'v');
+  break;
+}
+  }
+
+  if (!Ellipsis.empty()) {
+memcpy(pBuf, Ellipsis.data(), Ellipsis.size());
+pBuf += Ellipsis.size();
+  }
+  *pBuf++ = '"';
+
+  if (Ty->isWideCharType())
+Out << 'L';
+  else if (Ty->isChar8Type())
+Out << "u8";
+  else if (Ty->isChar16Type())
+Out << 'u';
+  else if (Ty->isChar32Type())
+Out << 'U';
+
+  Out << StringRef(Buf, pBuf - Buf);
+  return true;
+}
+
 void APValue::printPretty(raw_ostream &Out, const ASTContext &Ctx,
   QualType Ty) const {
   printPretty(Out, Ctx.getPrintingPolicy(), Ty, &Ctx);
@@ -795,17 +886,23 @@
   }
   case APValue::Array: {
 const ArrayType *AT = Ty->castAsArrayTypeUnsafe();
+unsigned N = getArrayInitializedElts();
+if (N != 0 &&
+TryPrintAsStringLiteral(Out, AT, &getArrayInitializedElt(0), N))
+  return;
 QualType ElemTy = AT->getElementType();
 Out << '{';
-if (unsigned N = getArrayInitializedElts()) {
-  getArrayInitializedElt(0).printPretty(Out, Policy, ElemTy, Ctx);
-  for (unsigned I = 1; I != N; ++I) {
+unsigned I = 0;
+switch (N) {
+case 0:
+  for (; I != N; ++I) {
 Out << ", ";
 if (I == 10) {
-  // Avoid printing out the entire contents of large arrays.
-  Out << "...";
-  break;
+  Out << "...}";
+  return;
 }
+LLVM_FALLTHROUGH;
+  default:
 getArrayInitializedElt(I).printPretty(Out, Policy, ElemTy, Ctx);
   }
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D115031: [AST] Print NTTP args as string-literals when possible

2021-12-03 Thread Zhihao Yuan via Phabricator via cfe-commits
lichray updated this revision to Diff 391602.
lichray added a comment.

Restore deleted comment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115031

Files:
  clang/lib/AST/APValue.cpp

Index: clang/lib/AST/APValue.cpp
===
--- clang/lib/AST/APValue.cpp
+++ clang/lib/AST/APValue.cpp
@@ -625,6 +625,97 @@
   return V.convertToDouble();
 }
 
+static bool TryPrintAsStringLiteral(raw_ostream &Out, const ArrayType *ATy,
+const APValue *Data, size_t Size) {
+  if (Size == 0)
+return false;
+
+  QualType Ty = ATy->getElementType();
+  if (!Ty->isAnyCharacterType())
+return false;
+
+  // Nothing we can do about a sequence that is not null-terminated
+  if (!Data[--Size].getInt().isZero())
+return false;
+
+  constexpr size_t MaxN = 36;
+  char Buf[MaxN * 2 + 3] = {'"'}; // "At most 36 escaped chars" + \0
+  auto *pBuf = Buf + 1;
+
+  // Better than printing a two-digit sequence of 10 integers.
+  StringRef Ellipsis;
+  if (Size > MaxN) {
+Ellipsis = " [...]";
+Size = std::min(MaxN - Ellipsis.size(), Size);
+  }
+
+  auto writeEscape = [](char *Ptr, char Ch) {
+Ptr[0] = '\\';
+Ptr[1] = Ch;
+return Ptr + 2;
+  };
+
+  for (auto &Val : ArrayRef(Data, Size)) {
+auto Char64 = Val.getInt().getExtValue();
+if (Char64 > 0x7f)
+  return false; // Bye bye, see you in integers.
+switch (auto Ch = static_cast(Char64)) {
+default:
+  if (isPrintable(Ch)) {
+*pBuf++ = Ch;
+break;
+  }
+  return false;
+case '\\':
+case '\'': // The diagnostic message is 'quoted'
+  pBuf = writeEscape(pBuf, Ch);
+  break;
+case '\0':
+  pBuf = writeEscape(pBuf, '0');
+  break;
+case '\a':
+  pBuf = writeEscape(pBuf, 'a');
+  break;
+case '\b':
+  pBuf = writeEscape(pBuf, 'b');
+  break;
+case '\f':
+  pBuf = writeEscape(pBuf, 'f');
+  break;
+case '\n':
+  pBuf = writeEscape(pBuf, 'n');
+  break;
+case '\r':
+  pBuf = writeEscape(pBuf, 'r');
+  break;
+case '\t':
+  pBuf = writeEscape(pBuf, 't');
+  break;
+case '\v':
+  pBuf = writeEscape(pBuf, 'v');
+  break;
+}
+  }
+
+  if (!Ellipsis.empty()) {
+memcpy(pBuf, Ellipsis.data(), Ellipsis.size());
+pBuf += Ellipsis.size();
+  }
+  *pBuf++ = '"';
+
+  if (Ty->isWideCharType())
+Out << 'L';
+  else if (Ty->isChar8Type())
+Out << "u8";
+  else if (Ty->isChar16Type())
+Out << 'u';
+  else if (Ty->isChar32Type())
+Out << 'U';
+
+  Out << StringRef(Buf, pBuf - Buf);
+  return true;
+}
+
 void APValue::printPretty(raw_ostream &Out, const ASTContext &Ctx,
   QualType Ty) const {
   printPretty(Out, Ctx.getPrintingPolicy(), Ty, &Ctx);
@@ -795,17 +886,24 @@
   }
   case APValue::Array: {
 const ArrayType *AT = Ty->castAsArrayTypeUnsafe();
+unsigned N = getArrayInitializedElts();
+if (N != 0 &&
+TryPrintAsStringLiteral(Out, AT, &getArrayInitializedElt(0), N))
+  return;
 QualType ElemTy = AT->getElementType();
 Out << '{';
-if (unsigned N = getArrayInitializedElts()) {
-  getArrayInitializedElt(0).printPretty(Out, Policy, ElemTy, Ctx);
-  for (unsigned I = 1; I != N; ++I) {
+unsigned I = 0;
+switch (N) {
+case 0:
+  for (; I != N; ++I) {
 Out << ", ";
 if (I == 10) {
   // Avoid printing out the entire contents of large arrays.
-  Out << "...";
-  break;
+  Out << "...}";
+  return;
 }
+LLVM_FALLTHROUGH;
+  default:
 getArrayInitializedElt(I).printPretty(Out, Policy, ElemTy, Ctx);
   }
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D91000: [clang-tidy] Add cert-msc24-c checker.

2021-12-03 Thread Fütő Gergely via Phabricator via cfe-commits
futogergely updated this revision to Diff 391604.

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

https://reviews.llvm.org/D91000

Files:
  clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
  clang-tools-extra/clang-tidy/cert/CMakeLists.txt
  clang-tools-extra/clang-tidy/cert/ObsolescentFunctionsCheck.cpp
  clang-tools-extra/clang-tidy/cert/ObsolescentFunctionsCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/cert-msc24-c.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/checkers/cert-msc24-c.c

Index: clang-tools-extra/test/clang-tidy/checkers/cert-msc24-c.c
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/cert-msc24-c.c
@@ -0,0 +1,97 @@
+// RUN: %check_clang_tidy -check-suffix=WITH-ANNEX-K%s cert-msc24-c %t -- -- -D__STDC_LIB_EXT1__=1 -D__STDC_WANT_LIB_EXT1__=1
+// RUN: %check_clang_tidy -check-suffix=WITHOUT-ANNEX-K %s cert-msc24-c %t -- -- -U__STDC_LIB_EXT1__   -U__STDC_WANT_LIB_EXT1__
+// RUN: %check_clang_tidy -check-suffix=WITHOUT-ANNEX-K %s cert-msc24-c %t -- -- -D__STDC_LIB_EXT1__=1 -U__STDC_WANT_LIB_EXT1__
+// RUN: %check_clang_tidy -check-suffix=WITHOUT-ANNEX-K %s cert-msc24-c %t -- -- -U__STDC_LIB_EXT1__   -D__STDC_WANT_LIB_EXT1__=1
+
+typedef void *FILE;
+char *gets(char *s);
+void rewind(FILE *stream);
+void setbuf(FILE *stream, char *buf);
+
+void f1(char *s, FILE *f) {
+  gets(s);
+  // CHECK-MESSAGES-WITH-ANNEX-K::[[@LINE-1]]:3: warning: function 'gets' is deprecated as of C99, removed from C11.
+  // CHECK-MESSAGES-WITHOUT-ANNEX-K: :[[@LINE-2]]:3: warning: function 'gets' is deprecated as of C99, removed from C11.
+
+  rewind(f);
+  // CHECK-MESSAGES-WITH-ANNEX-K::[[@LINE-1]]:3: warning: function 'rewind' has no error detection; 'fseek' should be used instead.
+  // CHECK-MESSAGES-WITHOUT-ANNEX-K: :[[@LINE-2]]:3: warning: function 'rewind' has no error detection; 'fseek' should be used instead.
+
+  setbuf(f, s);
+  // CHECK-MESSAGES-WITH-ANNEX-K::[[@LINE-1]]:3: warning: function 'setbuf' has no error detection; 'setvbuf' should be used instead.
+  // CHECK-MESSAGES-WITHOUT-ANNEX-K: :[[@LINE-2]]:3: warning: function 'setbuf' has no error detection; 'setvbuf' should be used instead.
+}
+
+struct tm;
+char *asctime(const struct tm *timeptr);
+
+void f2(const struct tm *timeptr) {
+  asctime(timeptr);
+  // CHECK-MESSAGES-WITH-ANNEX-K: :[[@LINE-1]]:3: warning: function 'asctime' is non-reentrant; 'asctime_s' should be used instead.
+  // no-warning WITHOUT-ANNEX-K
+
+  char *(*f_ptr1)(const struct tm *) = asctime;
+  // CHECK-MESSAGES-WITH-ANNEX-K: :[[@LINE-1]]:40: warning: function 'asctime' is non-reentrant; 'asctime_s' should be used instead.
+  // no-warning WITHOUT-ANNEX-K
+
+  char *(*f_ptr2)(const struct tm *) = &asctime;
+  // CHECK-MESSAGES-WITH-ANNEX-K: :[[@LINE-1]]:41: warning: function 'asctime' is non-reentrant; 'asctime_s' should be used instead.
+  // no-warning WITHOUT-ANNEX-K
+}
+
+FILE *fopen(const char *filename, const char *mode);
+FILE *freopen(const char *filename, const char *mode, FILE *stream);
+int fscanf(FILE *stream, const char *format, ...);
+
+void f3(char *s, FILE *f) {
+  fopen(s, s);
+  // CHECK-MESSAGES-WITH-ANNEX-K: :[[@LINE-1]]:3: warning: function 'fopen' has no exclusive access to file; 'fopen_s' should be used instead.
+  // no-warning WITHOUT-ANNEX-K
+
+  freopen(s, s, f);
+  // CHECK-MESSAGES-WITH-ANNEX-K: :[[@LINE-1]]:3: warning: function 'freopen' has no exclusive access to file; 'freopen_s' should be used instead.
+  // no-warning WITHOUT-ANNEX-K
+
+  int i;
+  fscanf(f, "%d", &i);
+  // CHECK-MESSAGES-WITH-ANNEX-K: :[[@LINE-1]]:3: warning: function 'fscanf' is obsolescent; 'fscanf_s' should be used instead.
+  // no-warning WITHOUT-ANNEX-K
+}
+
+typedef int time_t;
+char *ctime(const time_t *timer);
+
+void f4(const time_t *timer) {
+  ctime(timer);
+  // CHECK-MESSAGES-WITH-ANNEX-K: :[[@LINE-1]]:3: warning: function 'ctime' is non-reentrant; 'ctime_s' should be used instead.
+  // no-warning WITHOUT-ANNEX-K
+}
+
+typedef int errno_t;
+typedef __SIZE_TYPE__ size_t;
+typedef size_t rsize_t;
+errno_t asctime_s(char *s, rsize_t maxsize, const struct tm *timeptr);
+errno_t strcat_s(char *s1, rsize_t s1max, const char *s2);
+int fseek(FILE *stream, long int offset, int whence);
+int setvbuf(FILE *stream, char *buf, int mode, size_t size);
+
+void fUsingSafeFunctions(const struct tm *timeptr, FILE *f) {
+  const size_t BUFFSIZE = 32;
+  char buf[BUFFSIZE] = {0};
+
+  // no-warning, safe function from annex K is used
+  if (asctime_s(buf, BUFFSIZE, timeptr) != 0)
+return;
+
+  // no-warning, safe function from annex K is used
+  if (strcat_s(buf, BUFFSIZE, "something") != 0)
+return;
+
+  // no-warning, fseeks supports error checking
+  if (fseek(f, 0, 0) != 0)
+return;
+
+  // no-warning, setvbuf supports error checking
+  if (setvbuf(f, buf,

[PATCH] D91000: [clang-tidy] Add cert-msc24-c checker.

2021-12-03 Thread Fütő Gergely via Phabricator via cfe-commits
futogergely marked an inline comment as done.
futogergely added inline comments.



Comment at: clang-tools-extra/clang-tidy/cert/ObsolescentFunctionsCheck.cpp:48
+  // Matching functions with safe replacements in annex K.
+  auto FunctionNamesWithAnnexKReplacementMatcher = hasAnyName(
+  "::asctime", "::ctime", "::fopen", "::freopen", "::bsearch", "::fprintf",

whisperity wrote:
> Is this ordering specific in any way? Is the rule listing them in this order? 
> If not, can we have them listed alphabetically, for easier search and 
> potential later change?
done



Comment at: clang-tools-extra/docs/clang-tidy/checks/cert-msc24-c.rst:10
+For the listed functions, an alternative, more secure replacement is 
suggested, if available.
+The checker heavily relies on the functions from annex K (Bounds-checking 
interfaces) of C11.
+

whisperity wrote:
> (And consistent capitalisation later.)
done


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

https://reviews.llvm.org/D91000

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


[PATCH] D106585: Fix clang debug info irgen of i128 enums

2021-12-03 Thread Mike Hommey via Phabricator via cfe-commits
glandium added a comment.

So far, what I've found is that in some cases, DIEnumerator::get returns the 
same node for similar enumerator values in different enums that happen to have 
the same name and value (even if their bitwidth differs), but sometimes not.
For example, in one compilation I see:

  DIEnumerator::get (Name={Data@0x5575ee17ea38="nsNumberControlFrame_id", 
Length=23}, IsUnsigned: optimized out, Value={U={VAL=50, pVal=0x32}, 
BitWidth=8}, Context@0x5575e8305da0.pImpl=0x5575e8307230) = 0x55760563a708
  DIEnumerator::get (Name={Data@0x5575ee17ea38="nsNumberControlFrame_id", 
Length=23}, IsUnsigned: optimized out, Value={U={VAL=50, pVal=0x32}, 
BitWidth=32}, Context@0x5575e8305da0.pImpl=0x5575e8307230) = 0x5576067e7148

In another compilation of the same file with the same flags:

  DIEnumerator::get (Name={Data@0x561c659e0cc8="nsNumberControlFrame_id", 
Length=23}, IsUnsigned: optimized out, Value={U={VAL=50, pVal=0x32}, 
BitWidth=8}, Context@0x561c5fb68da0.pImpl=0x561c5fb6a230) = 0x561c7ce9dbf8
  DIEnumerator::get (Name={Data@0x561c659e0cc8="nsNumberControlFrame_id", 
Length=23}, IsUnsigned: optimized out, Value={U={VAL=50, pVal=0x32}, 
BitWidth=32}, Context@0x561c5fb68da0.pImpl=0x561c5fb6a230) = 0x561c7ce9dbf8


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106585

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


[PATCH] D91000: [clang-tidy] Add cert-msc24-c checker.

2021-12-03 Thread Fütő Gergely via Phabricator via cfe-commits
futogergely marked an inline comment as done.
futogergely added a comment.

In D91000#3161296 , @whisperity wrote:

> Should/does this work in C++ mode for `std::whatever`?

Right now the checker finds the functions in the global namespace only. The 
recommendation is listed only in the C part of the CERT rules, and as far as I 
know, Annex K functions are defined in the global namespace only, (or at least 
based on the standard). I can't really decide if the checker should look for 
the functions in the std namespace as well or not...


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

https://reviews.llvm.org/D91000

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


[PATCH] D108621: [HIPSPV] Add CUDA->SPIR-V address space mapping

2021-12-03 Thread Henry Linjamäki via Phabricator via cfe-commits
linjamaki added a comment.

Thanks, @Anastasia.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108621

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


[PATCH] D109818: [HIPSPV] Convert HIP kernels to SPIR-V kernels

2021-12-03 Thread Henry Linjamäki via Phabricator via cfe-commits
linjamaki added a comment.

The patch is ready to land. @Anastasia, @bader, could you commit this patch to 
the LLVM for us? Thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109818

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


[PATCH] D115014: [clang] RFC: NFC: simplify macro tokens assignment

2021-12-03 Thread zhouyizhou via Phabricator via cfe-commits
zhouyizhou added a comment.

In D115014#3169444 , @simon_tatham 
wrote:

> Ah, now I see what you mean – I didn't look far enough!
>
> I don't know this code well (in fact I'm not sure why you picked me as a 
> reviewer), but off the top of my head: the question is not just whether 
> `tokens_iterator` happens to be the same thing as `const Token *` //now//. 
> It's whether it's guaranteed to stay that way in the future.
>
> One of the purposes of these iterator types is that they form an opaque 
> abstraction layer: the client uses the type in only the ways that are 
> guaranteed to work by the iterator specification, and then the implementation 
> can completely change without breaking any client.
>
> If you make a change like this, and later `SmallVector::iterator` changes to 
> some other legal implementation, or `tokens_iterator` changes to be something 
> other than a `SmallVector::iterator`, then this change will have to be 
> reverted.

Thank Simon for resolve my confusion

I am crystal clear about the use of &* pair now. I did benefit a lot.

I pick you as a reviewer because you have committed to TokenLexer.cpp recently 
(I use git log along with git blame );-)

Thanks again
Zhouyi


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115014

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


[PATCH] D91000: [clang-tidy] Add cert-msc24-c checker.

2021-12-03 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

L129 and L135 are uncovered by tests. The rest of the lines are covered by 
tests, according to `lcov`.

The checker produced in total 15 reports on these 18 projects:
`memcached,tmux,curl,twin,vim,openssl,sqlite,ffmpeg,postgres,tinyxml2,libwebm,xerces,bitcoin,protobuf,qtbase,codechecker,contour,llvm-project`
You can check the reports by following this link:
https://codechecker-demo.eastus.cloudapp.azure.com/Default/reports?is-unique=on&detection-status=New&detection-status=Reopened&detection-status=Unresolved&run=%2aD91000-diff-4&checker-name=cert-msc24-c&diff-type=New

It seems like none of these projects actually use the //annex K// functions, 
which is not really a surprise.
VLC  and lighttpd 
 seems to use it. @futogergely could 
you please run your check on those projects?




Comment at: clang-tools-extra/docs/clang-tidy/checks/cert-msc24-c.rst:13
+For the following functions, replacement is suggested from annex K: `asctime`, 
+`ctime`, `fopen`, `freopen`, `bsearch`, `fprintf`, `fscanf`, `fwprintf`, 
`fwscanf`, 
+`getenv`, `gmtime`, `localtime`, `mbsrtowcs`, `mbstowcs`, `memcpy`, `memmove`, 
`printf`, 

remove trailing whitespaces


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

https://reviews.llvm.org/D91000

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


[PATCH] D106585: Fix clang debug info irgen of i128 enums

2021-12-03 Thread Mike Hommey via Phabricator via cfe-commits
glandium added a comment.

Reduced testcase:

  enum FrameIID {
nsBox_id,
nsIFrame_id,
nsHTMLFramesetBlankFrame_id,
nsHTMLFramesetBorderFrame_id,
  };
  
  enum class ClassID : unsigned char {
nsBox_id,
nsIFrame_id,
nsHTMLFramesetBlankFrame_id,
nsHTMLFramesetBorderFrame_id,
  };
  
  extern void foo(FrameIID, ClassID);
  
  void bar(FrameIID f, ClassID c) { foo(f, c); }

Compile with `clang++ -o test.ll -S -emit-llvm -g test.cpp` a number of times, 
and observe that sometimes the output is different. Add items to the enums to 
make it more frequent.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106585

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


[PATCH] D114713: [AArch64][SVE][NEON] Add NEON-SVE-Bridge intrinsics

2021-12-03 Thread Matt Devereau via Phabricator via cfe-commits
MattDevereau updated this revision to Diff 391616.
MattDevereau added a comment.

run clang format to fix test macro


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114713

Files:
  clang/include/clang/Basic/BuiltinsAArch64NeonSVEBridge.def
  clang/include/clang/Basic/BuiltinsAArch64NeonSVEBridge_cg.def
  clang/include/clang/Basic/BuiltinsSVE.def
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Headers/arm_neon_sve_bridge.h
  
clang/test/CodeGen/aarch64_neon_sve_bridge_intrinsics/acle_neon_sve_bridge_dup_neonq.c
  
clang/test/CodeGen/aarch64_neon_sve_bridge_intrinsics/acle_neon_sve_bridge_get_neonq.c
  
clang/test/CodeGen/aarch64_neon_sve_bridge_intrinsics/acle_neon_sve_bridge_set_neonq.c

Index: clang/test/CodeGen/aarch64_neon_sve_bridge_intrinsics/acle_neon_sve_bridge_set_neonq.c
===
--- /dev/null
+++ clang/test/CodeGen/aarch64_neon_sve_bridge_intrinsics/acle_neon_sve_bridge_set_neonq.c
@@ -0,0 +1,183 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// REQUIRES: aarch64-registered-target
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +neon -target-feature +sve -target-feature +bf16 -fallow-half-arguments-and-returns -S -O1 -Werror -Wall -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +neon -target-feature +sve -target-feature +bf16 -fallow-half-arguments-and-returns -S -O1 -Werror -Wall -emit-llvm -o - -x c++ %s | FileCheck %s -check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +neon -target-feature +sve -target-feature +bf16 -fallow-half-arguments-and-returns -S -O1 -Werror -Wall -o /dev/null %s
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu -target-feature +neon -target-feature +sve -target-feature +bf16 -fallow-half-arguments-and-returns -S -O1 -Werror -Wall -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu -target-feature +neon -target-feature +sve -target-feature +bf16 -fallow-half-arguments-and-returns -S -O1 -Werror -Wall -emit-llvm -o - -x c++ %s | FileCheck %s -check-prefix=CPP-CHECK
+#include 
+
+#ifdef SVE_OVERLOADED_FORMS
+// A simple used,unused... macro, long enough to represent any SVE builtin.
+#define SVE_ACLE_FUNC(A1, A2_UNUSED, A3, A4_UNUSED) A1##A3
+#else
+#define SVE_ACLE_FUNC(A1, A2, A3, A4) A1##A2##A3##A4
+#endif
+
+// CHECK-LABEL: @test_svset_neonq_s8(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = call  @llvm.experimental.vector.insert.nxv16i8.v16i8( [[S:%.*]], <16 x i8> [[N:%.*]], i64 0)
+// CHECK-NEXT:ret  [[TMP0]]
+//
+// CPP-CHECK-LABEL: @_Z19test_svset_neonq_s8u10__SVInt8_t11__Int8x16_t(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = call  @llvm.experimental.vector.insert.nxv16i8.v16i8( [[S:%.*]], <16 x i8> [[N:%.*]], i64 0)
+// CPP-CHECK-NEXT:ret  [[TMP0]]
+//
+svint8_t test_svset_neonq_s8(svint8_t s, int8x16_t n) {
+  return SVE_ACLE_FUNC(svset_neonq, _s8, , )(s, n);
+}
+
+// CHECK-LABEL: @test_svset_neonq_s16(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = call  @llvm.experimental.vector.insert.nxv8i16.v8i16( [[S:%.*]], <8 x i16> [[N:%.*]], i64 0)
+// CHECK-NEXT:ret  [[TMP0]]
+//
+// CPP-CHECK-LABEL: @_Z20test_svset_neonq_s16u11__SVInt16_t11__Int16x8_t(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = call  @llvm.experimental.vector.insert.nxv8i16.v8i16( [[S:%.*]], <8 x i16> [[N:%.*]], i64 0)
+// CPP-CHECK-NEXT:ret  [[TMP0]]
+//
+svint16_t test_svset_neonq_s16(svint16_t s, int16x8_t n) {
+  return SVE_ACLE_FUNC(svset_neonq, _s16, , )(s, n);
+}
+
+// CHECK-LABEL: @test_svset_neonq_s32(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = call  @llvm.experimental.vector.insert.nxv4i32.v4i32( [[S:%.*]], <4 x i32> [[N:%.*]], i64 0)
+// CHECK-NEXT:ret  [[TMP0]]
+//
+// CPP-CHECK-LABEL: @_Z20test_svset_neonq_s32u11__SVInt32_t11__Int32x4_t(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = call  @llvm.experimental.vector.insert.nxv4i32.v4i32( [[S:%.*]], <4 x i32> [[N:%.*]], i64 0)
+// CPP-CHECK-NEXT:ret  [[TMP0]]
+//
+svint32_t test_svset_neonq_s32(svint32_t s, int32x4_t n) {
+  return SVE_ACLE_FUNC(svset_neonq, _s32, , )(s, n);
+}
+
+// CHECK-LABEL: @test_svset_neonq_s64(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = call  @llvm.experimental.vector.insert.nxv2i64.v2i64( [[S:%.*]], <2 x i64> [[N:%.*]], i64 0)
+// CHECK-NEXT:ret  [[TMP0]]
+//
+// CPP-CHECK-LABEL: @_Z20test_svset_neonq_s64u11__SVInt64_t11__Int64x2_t(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = call  @llvm.experimental.vector.insert.nxv2i64.v2i64( [[S:%.*]], <2 x i64> [[N:%.*]], i64 0)
+// CPP-CHECK-NEXT:ret  [[TMP0]]
+//
+svint64

[PATCH] D115015: CodeGen: Strip exception specifications from function types in CFI type names.

2021-12-03 Thread Nico Weber via Phabricator via cfe-commits
thakis accepted this revision.
thakis added a comment.
This revision is now accepted and ready to land.

lg


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115015

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


[PATCH] D115039: [HIP] Fix -fgpu-rdc for Windows

2021-12-03 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl created this revision.
yaxunl added a reviewer: tra.
yaxunl requested review of this revision.

This patch fixes issues for -fgpu-rdc for Windows MSVC
toolchain:

Fix COFF specific section flags and remove section types
in llvm-mc input file for Windows.

Escape fatbin path in llvm-mc input file.

Add -triple option to llvm-mc.

Put `__hip_gpubin_handle` in comdat when it has linkonce_odr
linkage.


https://reviews.llvm.org/D115039

Files:
  clang/lib/CodeGen/CGCUDANV.cpp
  clang/lib/Driver/ToolChains/HIP.cpp
  clang/test/CodeGenCUDA/device-stub.cu
  clang/test/Driver/hip-toolchain-rdc.hip

Index: clang/test/Driver/hip-toolchain-rdc.hip
===
--- clang/test/Driver/hip-toolchain-rdc.hip
+++ clang/test/Driver/hip-toolchain-rdc.hip
@@ -11,14 +11,31 @@
 // RUN:   -fhip-dump-offload-linker-script \
 // RUN:   %S/Inputs/hip_multiple_inputs/a.cu \
 // RUN:   %S/Inputs/hip_multiple_inputs/b.hip \
-// RUN: 2>&1 | FileCheck %s
+// RUN: 2>&1 | FileCheck -check-prefixes=CHECK,LNX %s
+
+// RUN: %clang -### -target x86_64-pc-windows-msvc \
+// RUN:   -x hip --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 \
+// RUN:   --hip-device-lib=lib1.bc --hip-device-lib=lib2.bc \
+// RUN:   --hip-device-lib-path=%S/Inputs/hip_multiple_inputs/lib1 \
+// RUN:   --hip-device-lib-path=%S/Inputs/hip_multiple_inputs/lib2 \
+// RUN:   -fuse-ld=lld -fgpu-rdc -nogpuinc \
+// RUN:   -fhip-dump-offload-linker-script \
+// RUN:   %S/Inputs/hip_multiple_inputs/a.cu \
+// RUN:   %S/Inputs/hip_multiple_inputs/b.hip \
+// RUN: 2>&1 | FileCheck -check-prefixes=CHECK,MSVC %s
 
 // check code object alignment in dumped llvm-mc input
-// CHECK: .protected __hip_fatbin
+// LNX: .protected __hip_fatbin
+// LNX: .type __hip_fatbin,@object
+// LNX: .section .hip_fatbin,"a",@progbits
+// MSVC: .section .hip_fatbin, "dw"
+// CHECK: .globl __hip_fatbin
 // CHECK: .p2align 12
+// CHECK: __hip_fatbin:
+// CHECK: .incbin "[[BUNDLE:.*hipfb]]"
 
 // emit objects for host side path
-// CHECK: [[CLANG:".*clang.*"]] "-cc1" "-triple" "x86_64-unknown-linux-gnu"
+// CHECK: [[CLANG:".*clang.*"]] "-cc1" "-triple" [[HOST:"x86_64-[^"]+"]]
 // CHECK-SAME: "-aux-triple" "amdgcn-amd-amdhsa"
 // CHECK-SAME: "-emit-obj"
 // CHECK-SAME: {{.*}} "-main-file-name" "a.cu"
@@ -26,7 +43,7 @@
 // CHECK-SAME: {{.*}} "-o" [[A_OBJ_HOST:".*o"]] "-x" "hip"
 // CHECK-SAME: {{.*}} [[A_SRC:".*a.cu"]]
 
-// CHECK: [[CLANG]] "-cc1" "-triple" "x86_64-unknown-linux-gnu"
+// CHECK: [[CLANG]] "-cc1" "-triple" [[HOST]]
 // CHECK-SAME: "-aux-triple" "amdgcn-amd-amdhsa"
 // CHECK-SAME: "-emit-obj"
 // CHECK-SAME: {{.*}} "-main-file-name" "b.hip"
@@ -36,7 +53,7 @@
 
 // generate image for device side path on gfx803
 // CHECK: [[CLANG]] "-cc1" "-triple" "amdgcn-amd-amdhsa"
-// CHECK-SAME: "-aux-triple" "x86_64-unknown-linux-gnu"
+// CHECK-SAME: "-aux-triple" [[HOST:"x86_64-[^"]+"]]
 // CHECK-SAME: "-emit-llvm-bc"
 // CHECK-SAME: {{.*}} "-main-file-name" "a.cu"
 // CHECK-SAME: "-fcuda-is-device" "-fcuda-allow-variadic-functions" "-fvisibility" "hidden"
@@ -48,7 +65,7 @@
 // CHECK-SAME: {{.*}} [[A_SRC]]
 
 // CHECK: [[CLANG]] "-cc1" "-triple" "amdgcn-amd-amdhsa"
-// CHECK-SAME: "-aux-triple" "x86_64-unknown-linux-gnu"
+// CHECK-SAME: "-aux-triple" [[HOST]]
 // CHECK-SAME: "-emit-llvm-bc"
 // CHECK-SAME: {{.*}} "-main-file-name" "b.hip"
 // CHECK-SAME: "-fcuda-is-device" "-fcuda-allow-variadic-functions" "-fvisibility" "hidden"
@@ -68,7 +85,7 @@
 
 // generate image for device side path on gfx900
 // CHECK: [[CLANG]] "-cc1" "-triple" "amdgcn-amd-amdhsa"
-// CHECK-SAME: "-aux-triple" "x86_64-unknown-linux-gnu"
+// CHECK-SAME: "-aux-triple" [[HOST]]
 // CHECK-SAME: "-emit-llvm-bc"
 // CHECK-SAME: {{.*}} "-main-file-name" "a.cu"
 // CHECK-SAME: "-fcuda-is-device"
@@ -78,7 +95,7 @@
 // CHECK-SAME: {{.*}} [[A_SRC]]
 
 // CHECK: [[CLANG]] "-cc1" "-triple" "amdgcn-amd-amdhsa"
-// CHECK-SAME: "-aux-triple" "x86_64-unknown-linux-gnu"
+// CHECK-SAME: "-aux-triple" [[HOST]]
 // CHECK-SAME: "-emit-llvm-bc"
 // CHECK-SAME: {{.*}} "-main-file-name" "b.hip"
 // CHECK-SAME: "-fcuda-is-device"
@@ -99,9 +116,10 @@
 // CHECK: [[BUNDLER:".*clang-offload-bundler"]] "-type=o"
 // CHECK-SAME: "-bundle-align=4096"
 // CHECK-SAME: "-targets={{.*}},hipv4-amdgcn-amd-amdhsa--gfx803,hipv4-amdgcn-amd-amdhsa--gfx900"
-// CHECK-SAME: "-inputs={{.*}},[[IMG_DEV1]],[[IMG_DEV2]]" "-outputs=[[BUNDLE:.*hipfb]]"
+// CHECK-SAME: "-inputs={{.*}},[[IMG_DEV1]],[[IMG_DEV2]]" "-outputs=[[BUNDLE]]"
 
-// CHECK: [[MC:".*llvm-mc.*"]] "-o" [[OBJBUNDLE:".*o"]] "{{.*}}.mcin" "--filetype=obj"
+// CHECK: [[MC:".*llvm-mc.*"]] "-triple" [[HOST]] "-o" [[OBJBUNDLE:".*o"]] "{{.*}}.mcin" "--filetype=obj"
 
 // output the executable
-// CHECK: [[LD:".*ld.*"]] {{.*}}"-o" "a.out" {{.*}} [[A_OBJ_HOST]] [[B_OBJ_HOST]] [[OBJBUNDLE]]
+// LNX: [[LD:".*ld.*"]] {{.*}}"-o" "a.out" {{.*}} [[A_OBJ_HOST]] [[B_OBJ_HOST]] [[OBJBUNDLE]]
+// MSVC: [[LD:".*lld-link.*"]] {{.*}}"-out:a.exe" {{.*}} [[A_OBJ_HOST]] [[B_OBJ

[clang] f627956 - [OPENMP]Fix PR52117: Crash caused by target region inside of task construct.

2021-12-03 Thread Alexey Bataev via cfe-commits

Author: Alexey Bataev
Date: 2021-12-03T07:01:00-08:00
New Revision: f6279562dae456f6c58d5f7484ba4bae5c2071fa

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

LOG: [OPENMP]Fix PR52117: Crash caused by target region inside of task 
construct.

Need to do the analysis of the captured expressions in the clauses.
Previously the compiler ignored them and it may lead to a compiler crash
trying to get the address of the mapped variables.

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

Added: 
clang/test/OpenMP/task_target_device_codegen.c

Modified: 
clang/lib/Sema/SemaOpenMP.cpp
clang/test/Analysis/cfg-openmp.cpp
clang/test/OpenMP/taskloop_codegen.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index d3e3d1e2ffcb6..581b7c8841d33 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -3500,7 +3500,8 @@ class DSAAttrChecker final : public 
StmtVisitor {
   return;
 if (auto *VD = dyn_cast(E->getDecl())) {
   // Check the datasharing rules for the expressions in the clauses.
-  if (!CS) {
+  if (!CS || (isa(VD) && !CS->capturesVariable(VD) &&
+  !Stack->getTopDSA(VD, /*FromParent=*/false).RefExpr)) {
 if (auto *CED = dyn_cast(VD))
   if (!CED->hasAttr()) {
 Visit(CED->getInit());
@@ -3819,6 +3820,10 @@ class DSAAttrChecker final : public 
StmtVisitor {
   }
   void VisitOMPExecutableDirective(OMPExecutableDirective *S) {
 for (OMPClause *C : S->clauses()) {
+  // Skip analysis of arguments of private clauses for task|target
+  // directives.
+  if (isa_and_nonnull(C))
+continue;
   // Skip analysis of arguments of implicitly defined firstprivate clause
   // for task|target directives.
   // Skip analysis of arguments of implicitly defined map clause for target
@@ -3841,6 +3846,15 @@ class DSAAttrChecker final : public 
StmtVisitor {
 VisitStmt(S);
   }
 
+  void VisitCallExpr(CallExpr *S) {
+for (Stmt *C : S->arguments()) {
+  if (C) {
+// Check implicitly captured variables in the task-based directives to
+// check if they must be firstprivatized.
+Visit(C);
+  }
+}
+  }
   void VisitStmt(Stmt *S) {
 for (Stmt *C : S->children()) {
   if (C) {

diff  --git a/clang/test/Analysis/cfg-openmp.cpp 
b/clang/test/Analysis/cfg-openmp.cpp
index 9e61d656698b9..353efbec919bc 100644
--- a/clang/test/Analysis/cfg-openmp.cpp
+++ b/clang/test/Analysis/cfg-openmp.cpp
@@ -598,19 +598,19 @@ void tls(int argc) {
 void tdpf(int argc) {
   int x, cond, fp, rd, lin, step, map;
 // CHECK-DAG:   [B1]
-// CHECK-DAG:  [[#TDPF:]]: cond
-// CHECK-DAG:  [[#TDPF+1]]: [B1.[[#TDPF]]] (ImplicitCastExpr, LValueToRValue, 
int)
+// CHECK-DAG:  [[#TDPF:]]: [B1.{{.+}}]
+// CHECK-DAG:  [[#TDPF+1]]: [B1.[[#TDPF+6]]] (ImplicitCastExpr, 
LValueToRValue, int)
 // CHECK-DAG:  [[#TDPF+2]]: [B1.[[#TDPF+1]]] (ImplicitCastExpr, 
IntegralToBoolean, _Bool)
-// CHECK-DAG:  [[#TDPF+3]]: [B1.[[#TDPF+6]]]
-// CHECK-DAG:  [[#TDPF+4]]: [B1.[[#TDPF+7]]]
+// CHECK-DAG:  [[#TDPF+3]]: [B1.[[#TDPF+7]]]
+// CHECK-DAG:  [[#TDPF+4]]: [B1.[[#TDPF+8]]]
 // CHECK-DAG:  [[#TDPF+5]]: #pragma omp teams distribute parallel for if(cond) 
firstprivate(fp) reduction(+: rd)
 // CHECK-DAG:for (int i = 0;
 // CHECK-DAG:[B3.[[#TDPFB:]]];
-// CHECK-DAG:  [[#TDPF+6]]: fp
-// CHECK-DAG:  [[#TDPF+7]]: rd
-// CHECK-DAG:  [[#TDPF+8]]: argc
-// CHECK-DAG:  [[#TDPF+9]]: x
-// CHECK-DAG:  [[#TDPF+10]]: cond
+// CHECK-DAG:  [[#TDPF+6]]: cond
+// CHECK-DAG:  [[#TDPF+7]]: fp
+// CHECK-DAG:  [[#TDPF+8]]: rd
+// CHECK-DAG:  [[#TDPF+9]]: argc
+// CHECK-DAG:  [[#TDPF+10]]: x
 // CHECK-DAG:  [[#TDPF+11]]: #pragma omp target
 // CHECK-DAG:   [B3]
 // CHECK-DAG:  [[#TDPFB-3]]: x
@@ -627,19 +627,19 @@ void tdpf(int argc) {
 void tdpfs(int argc) {
   int x, cond, fp, rd, lin, step, map;
 // CHECK-DAG:   [B1]
-// CHECK-DAG:  [[#TDPFS:]]: cond
-// CHECK-DAG:  [[#TDPFS+1]]: [B1.[[#TDPFS]]] (ImplicitCastExpr, 
LValueToRValue, int)
+// CHECK-DAG:  [[#TDPFS:]]: [B1.{{.+}}]
+// CHECK-DAG:  [[#TDPFS+1]]: [B1.[[#TDPFS+6]]] (ImplicitCastExpr, 
LValueToRValue, int)
 // CHECK-DAG:  [[#TDPFS+2]]: [B1.[[#TDPFS+1]]] (ImplicitCastExpr, 
IntegralToBoolean, _Bool)
-// CHECK-DAG:  [[#TDPFS+3]]: [B1.[[#TDPFS+6]]]
-// CHECK-DAG:  [[#TDPFS+4]]: [B1.[[#TDPFS+7]]]
+// CHECK-DAG:  [[#TDPFS+3]]: [B1.[[#TDPFS+7]]]
+// CHECK-DAG:  [[#TDPFS+4]]: [B1.[[#TDPFS+8]]]
 // CHECK-DAG:  [[#TDPFS+5]]: #pragma omp teams distribute parallel for simd 
if(cond) firstprivate(fp) reduction(+: rd)
 // CHECK-DAG:for (int i = 0;
 // CHECK-DAG:[B3.[[#TDPFSB:]]];
-// CHECK-DAG:  [[#TDPFS+6]]: fp
-// CHECK-DAG:  [[#TDPFS+7]]: rd
-// CHECK-DAG:  [[#TDPFS+8]]: argc
-// 

[PATCH] D114546: [OPENMP]Fix PR52117: Crash caused by target region inside of task construct.

2021-12-03 Thread Alexey Bataev 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 rGf6279562dae4: [OPENMP]Fix PR52117: Crash caused by target 
region inside of task construct. (authored by ABataev).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114546

Files:
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/Analysis/cfg-openmp.cpp
  clang/test/OpenMP/task_target_device_codegen.c
  clang/test/OpenMP/taskloop_codegen.cpp

Index: clang/test/OpenMP/taskloop_codegen.cpp
===
--- clang/test/OpenMP/taskloop_codegen.cpp
+++ clang/test/OpenMP/taskloop_codegen.cpp
@@ -238,8 +238,8 @@
 // CHECK-LABEL: taskloop_with_class
 void taskloop_with_class() {
   St s1;
-  // CHECK: [[TD:%.+]] = call i8* @__kmpc_omp_task_alloc(%struct.ident_t* @{{.+}}, i32 [[GTID:%.+]], i32 1, i64 88, i64 8, i32 (i32, i8*)* bitcast (i32 (i32, [[TD_TYPE:%.+]]*)* @{{.+}} to i32 (i32, i8*)*))
-  // CHECK: call void @__kmpc_taskloop(%struct.ident_t* @{{.+}}, i32 [[GTID]], i8* [[TD]], i32 1, i64* %{{.+}}, i64* %{{.+}}, i64 %{{.+}}, i32 1, i32 0, i64 0, i8* bitcast (void ([[TD_TYPE]]*, [[TD_TYPE]]*, i32)* @{{.+}} to i8*))
+  // CHECK: [[TD:%.+]] = call i8* @__kmpc_omp_task_alloc(%struct.ident_t* @{{.+}}, i32 [[GTID:%.+]], i32 1, i64 80, i64 8, i32 (i32, i8*)* bitcast (i32 (i32, [[TD_TYPE:%.+]]*)* @{{.+}} to i32 (i32, i8*)*))
+  // CHECK: call void @__kmpc_taskloop(%struct.ident_t* @{{.+}}, i32 [[GTID]], i8* [[TD]], i32 1, i64* %{{.+}}, i64* %{{.+}}, i64 %{{.+}}, i32 1, i32 0, i64 0, i8* null)
 #pragma omp taskloop
   for (St s = St(); s < s1; s += 1) {
   }
Index: clang/test/OpenMP/task_target_device_codegen.c
===
--- /dev/null
+++ clang/test/OpenMP/task_target_device_codegen.c
@@ -0,0 +1,105 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --function-signature --include-generated-funcs --replace-value-regex "__omp_offloading_[0-9a-z]+_[0-9a-z]+" "reduction_size[.].+[.]" "pl_cond[   .].+[.|,]" --prefix-filecheck-ir-name _
+// RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -fopenmp -fopenmp-version=50 -x c -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -x c -triple x86_64-apple-darwin10 -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -x c -triple x86_64-apple-darwin10 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s
+
+// RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -fopenmp-simd -fopenmp-version=50 -x c -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 %s
+// RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=50 -x c -triple x86_64-apple-darwin10 -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=50 -x c -triple x86_64-apple-darwin10 -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s
+// SIMD-ONLY0-NOT: {{__kmpc|__tgt}}
+// expected-no-diagnostics
+#ifndef HEADER
+#define HEADER
+
+void test_task_affinity() {
+  int t;
+#pragma omp task
+  {
+#pragma omp target device(t)
+;
+  }
+}
+#endif
+// CHECK-LABEL: define {{[^@]+}}@test_task_affinity
+// CHECK-SAME: () #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[T:%.*]] = alloca i32, align 4
+// CHECK-NEXT:[[AGG_CAPTURED:%.*]] = alloca [[STRUCT_ANON:%.*]], align 1
+// CHECK-NEXT:[[TMP0:%.*]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @[[GLOB1:[0-9]+]])
+// CHECK-NEXT:[[TMP1:%.*]] = call i8* @__kmpc_omp_task_alloc(%struct.ident_t* @[[GLOB1]], i32 [[TMP0]], i32 1, i64 48, i64 0, i32 (i32, i8*)* bitcast (i32 (i32, %struct.kmp_task_t_with_privates*)* @.omp_task_entry. to i32 (i32, i8*)*))
+// CHECK-NEXT:[[TMP2:%.*]] = bitcast i8* [[TMP1]] to %struct.kmp_task_t_with_privates*
+// CHECK-NEXT:[[TMP3:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_T_WITH_PRIVATES:%.*]], %struct.kmp_task_t_with_privates* [[TMP2]], i32 0, i32 0
+// CHECK-NEXT:[[TMP4:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_T_WITH_PRIVATES]], %struct.kmp_task_t_with_privates* [[TMP2]], i32 0, i32 1
+// CHECK-NEXT:[[TMP5:%.*]] = getelementptr inbounds [[STRUCT__KMP_PRIVATES_T:%.*]], %struct..kmp_privates.t* [[TMP4]], i32 0, i32 0
+// CHECK-NEXT:[[TMP6:%.*]] = load i32, i32* [[T]], align 4
+// CHECK-NEXT:store i32 [[TMP6]], i32* [[TMP5]], align 8
+// CHECK-NEXT:[[TMP7:%.*]] = call i32 @__kmpc_omp_task(%struct.ident_t* @[[GLOB1]], i32 [[TMP0]], i8* [[TMP1]])
+// CHECK-NEXT:ret void
+//
+//
+// CHECK-LABEL: define {{[^@]+}}@{{__omp_offloading_[0-9a-z]+_[0-9a-z]+}}_test_task_affinity_l18
+// CHECK-SAME: () #[[ATTR1:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret void
+//
+//
+// CHECK-LABEL: define {{[^@]+}}@.omp_task_privates_map.
+// CHECK-SAME: (%struct..kmp_privates.t* noalias [[TMP0:%.*]], i32** noalias [[

[PATCH] D102090: [CMake][ELF] Link libLLVM.so and libclang-cpp.so with -Bsymbolic-functions

2021-12-03 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

In D102090#3169439 , @ebrevnov wrote:

> While -Bsymbolic-funtions brings nice performance improvements it also 
> changes symbol resolution order. That means we effectively disabled  
> preemption for functions and all references from inside libLLVM*.so will be 
> resolved locally.  But references to global data can still be interposed by 
> external definitions. Do I understand correctly that main argument against 
> using -Bsymbolic is potential issue with equality comparison of address of 
> global? Or anything else?

I think it has less to do with the uniqueness of the addresses and more to do 
with the deduplication of the global storage. If you have an inline C++ global 
variable present in LLVM's headers (think a static data member of a class 
template instantiation), things go wrong quickly if there are two copies of 
this global, one in LLVM, and the other in the user's binary. Updates from one 
DSO will not be visible in the other. If you arrange the same situation with 
functions, they are usually functionally equivalent even if there are minor 
code differences.

Generally, users are not trying to preempt LLVM's own function definitions. The 
typical use cases are to override C library functionality such as malloc. The 
performance benefit of -Bsymbolic-functions is worth making LLVM's own 
functions non-interposable.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102090

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


[PATCH] D114602: [clang-tidy][docs][NFC] Improve documentation of bugprone-unhandled-exception-at-new

2021-12-03 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 391640.
balazske marked 2 inline comments as done.
balazske added a comment.

Applied the text changes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114602

Files:
  
clang-tools-extra/docs/clang-tidy/checks/bugprone-unhandled-exception-at-new.rst


Index: 
clang-tools-extra/docs/clang-tidy/checks/bugprone-unhandled-exception-at-new.rst
===
--- 
clang-tools-extra/docs/clang-tidy/checks/bugprone-unhandled-exception-at-new.rst
+++ 
clang-tools-extra/docs/clang-tidy/checks/bugprone-unhandled-exception-at-new.rst
@@ -5,21 +5,51 @@
 
 Finds calls to ``new`` with missing exception handler for ``std::bad_alloc``.
 
+Calls to ``new`` may throw exceptions of type ``std::bad_alloc`` that should
+be handled. Alternatively, the nonthrowing form of ``new`` can be
+used. The check verifies that the exception is handled in the function
+that calls ``new``.
+
+If a nonthrowing version is used or the exception is allowed to propagate out
+of the function no warning is generated.
+
+The exception handler is checked if it catches a ``std::bad_alloc`` or
+``std::exception`` exception type, or all exceptions (catch-all).
+The check assumes that any user-defined ``operator new`` is either
+``noexcept`` or may throw an exception of type ``std::bad_alloc`` (or one
+derived from it). Other exception class types are not taken into account.
+
 .. code-block:: c++
 
   int *f() noexcept {
-int *p = new int[1000];
+int *p = new int[1000]; // warning: missing exception handler for 
allocation failure at 'new'
+// ...
+return p;
+  }
+
+.. code-block:: c++
+
+  int *f1() { // not 'noexcept'
+int *p = new int[1000]; // no warning: exception can be handled outside
+// of this function
+// ...
+return p;
+  }
+
+  int *f2() noexcept {
+try {
+  int *p = new int[1000]; // no warning: exception is handled
+  // ...
+  return p;
+} catch (std::bad_alloc &) {
+  // ...
+}
+// ...
+  }
+
+  int *f3() noexcept {
+int *p = new (std::nothrow) int[1000]; // no warning: "nothrow" is used
 // ...
 return p;
   }
 
-Calls to ``new`` can throw exceptions of type ``std::bad_alloc`` that should
-be handled by the code. Alternatively, the nonthrowing form of ``new`` can be
-used. The check verifies that the exception is handled in the function
-that calls ``new``, unless a nonthrowing version is used or the exception
-is allowed to propagate out of the function (exception handler is checked for
-types ``std::bad_alloc``, ``std::exception``, and catch-all handler).
-The check assumes that any user-defined ``operator new`` is either
-``noexcept`` or may throw an exception of type ``std::bad_alloc`` (or derived
-from it). Other exception types or exceptions occurring in the object's
-constructor are not taken into account.


Index: clang-tools-extra/docs/clang-tidy/checks/bugprone-unhandled-exception-at-new.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/bugprone-unhandled-exception-at-new.rst
+++ clang-tools-extra/docs/clang-tidy/checks/bugprone-unhandled-exception-at-new.rst
@@ -5,21 +5,51 @@
 
 Finds calls to ``new`` with missing exception handler for ``std::bad_alloc``.
 
+Calls to ``new`` may throw exceptions of type ``std::bad_alloc`` that should
+be handled. Alternatively, the nonthrowing form of ``new`` can be
+used. The check verifies that the exception is handled in the function
+that calls ``new``.
+
+If a nonthrowing version is used or the exception is allowed to propagate out
+of the function no warning is generated.
+
+The exception handler is checked if it catches a ``std::bad_alloc`` or
+``std::exception`` exception type, or all exceptions (catch-all).
+The check assumes that any user-defined ``operator new`` is either
+``noexcept`` or may throw an exception of type ``std::bad_alloc`` (or one
+derived from it). Other exception class types are not taken into account.
+
 .. code-block:: c++
 
   int *f() noexcept {
-int *p = new int[1000];
+int *p = new int[1000]; // warning: missing exception handler for allocation failure at 'new'
+// ...
+return p;
+  }
+
+.. code-block:: c++
+
+  int *f1() { // not 'noexcept'
+int *p = new int[1000]; // no warning: exception can be handled outside
+// of this function
+// ...
+return p;
+  }
+
+  int *f2() noexcept {
+try {
+  int *p = new int[1000]; // no warning: exception is handled
+  // ...
+  return p;
+} catch (std::bad_alloc &) {
+  // ...
+}
+// ...
+  }
+
+  int *f3() noexcept {
+int *p = new (std::nothrow) int[1000]; // no warning: "nothrow" is used
 // ...
 return p;
   }
 
-Calls to ``new`` can throw exceptions of type ``std::bad_alloc`` that

[PATCH] D114602: [clang-tidy][docs][NFC] Improve documentation of bugprone-unhandled-exception-at-new

2021-12-03 Thread Balázs Kéri 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 rG1cefe91d40ae: [clang-tidy][docs][NFC] Improve documentation 
of bugprone-unhandled-exception… (authored by balazske).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114602

Files:
  
clang-tools-extra/docs/clang-tidy/checks/bugprone-unhandled-exception-at-new.rst


Index: 
clang-tools-extra/docs/clang-tidy/checks/bugprone-unhandled-exception-at-new.rst
===
--- 
clang-tools-extra/docs/clang-tidy/checks/bugprone-unhandled-exception-at-new.rst
+++ 
clang-tools-extra/docs/clang-tidy/checks/bugprone-unhandled-exception-at-new.rst
@@ -5,21 +5,51 @@
 
 Finds calls to ``new`` with missing exception handler for ``std::bad_alloc``.
 
+Calls to ``new`` may throw exceptions of type ``std::bad_alloc`` that should
+be handled. Alternatively, the nonthrowing form of ``new`` can be
+used. The check verifies that the exception is handled in the function
+that calls ``new``.
+
+If a nonthrowing version is used or the exception is allowed to propagate out
+of the function no warning is generated.
+
+The exception handler is checked if it catches a ``std::bad_alloc`` or
+``std::exception`` exception type, or all exceptions (catch-all).
+The check assumes that any user-defined ``operator new`` is either
+``noexcept`` or may throw an exception of type ``std::bad_alloc`` (or one
+derived from it). Other exception class types are not taken into account.
+
 .. code-block:: c++
 
   int *f() noexcept {
-int *p = new int[1000];
+int *p = new int[1000]; // warning: missing exception handler for 
allocation failure at 'new'
+// ...
+return p;
+  }
+
+.. code-block:: c++
+
+  int *f1() { // not 'noexcept'
+int *p = new int[1000]; // no warning: exception can be handled outside
+// of this function
+// ...
+return p;
+  }
+
+  int *f2() noexcept {
+try {
+  int *p = new int[1000]; // no warning: exception is handled
+  // ...
+  return p;
+} catch (std::bad_alloc &) {
+  // ...
+}
+// ...
+  }
+
+  int *f3() noexcept {
+int *p = new (std::nothrow) int[1000]; // no warning: "nothrow" is used
 // ...
 return p;
   }
 
-Calls to ``new`` can throw exceptions of type ``std::bad_alloc`` that should
-be handled by the code. Alternatively, the nonthrowing form of ``new`` can be
-used. The check verifies that the exception is handled in the function
-that calls ``new``, unless a nonthrowing version is used or the exception
-is allowed to propagate out of the function (exception handler is checked for
-types ``std::bad_alloc``, ``std::exception``, and catch-all handler).
-The check assumes that any user-defined ``operator new`` is either
-``noexcept`` or may throw an exception of type ``std::bad_alloc`` (or derived
-from it). Other exception types or exceptions occurring in the object's
-constructor are not taken into account.


Index: clang-tools-extra/docs/clang-tidy/checks/bugprone-unhandled-exception-at-new.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/bugprone-unhandled-exception-at-new.rst
+++ clang-tools-extra/docs/clang-tidy/checks/bugprone-unhandled-exception-at-new.rst
@@ -5,21 +5,51 @@
 
 Finds calls to ``new`` with missing exception handler for ``std::bad_alloc``.
 
+Calls to ``new`` may throw exceptions of type ``std::bad_alloc`` that should
+be handled. Alternatively, the nonthrowing form of ``new`` can be
+used. The check verifies that the exception is handled in the function
+that calls ``new``.
+
+If a nonthrowing version is used or the exception is allowed to propagate out
+of the function no warning is generated.
+
+The exception handler is checked if it catches a ``std::bad_alloc`` or
+``std::exception`` exception type, or all exceptions (catch-all).
+The check assumes that any user-defined ``operator new`` is either
+``noexcept`` or may throw an exception of type ``std::bad_alloc`` (or one
+derived from it). Other exception class types are not taken into account.
+
 .. code-block:: c++
 
   int *f() noexcept {
-int *p = new int[1000];
+int *p = new int[1000]; // warning: missing exception handler for allocation failure at 'new'
+// ...
+return p;
+  }
+
+.. code-block:: c++
+
+  int *f1() { // not 'noexcept'
+int *p = new int[1000]; // no warning: exception can be handled outside
+// of this function
+// ...
+return p;
+  }
+
+  int *f2() noexcept {
+try {
+  int *p = new int[1000]; // no warning: exception is handled
+  // ...
+  return p;
+} catch (std::bad_alloc &) {
+  // ...
+}
+// ...
+  }
+
+  int *f3() noexcept {
+int *p = new (std::nothrow) int[1000]; // no warning:

[clang-tools-extra] 1cefe91 - [clang-tidy][docs][NFC] Improve documentation of bugprone-unhandled-exception-at-new

2021-12-03 Thread Balázs Kéri via cfe-commits

Author: Balázs Kéri
Date: 2021-12-03T16:53:08+01:00
New Revision: 1cefe91d40aef043ec949c6ddb053b47b4d5b8e6

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

LOG: [clang-tidy][docs][NFC] Improve documentation of 
bugprone-unhandled-exception-at-new

Reviewed By: aaron.ballman

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

Added: 


Modified: 

clang-tools-extra/docs/clang-tidy/checks/bugprone-unhandled-exception-at-new.rst

Removed: 




diff  --git 
a/clang-tools-extra/docs/clang-tidy/checks/bugprone-unhandled-exception-at-new.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/bugprone-unhandled-exception-at-new.rst
index 63747ec7602e..b818281c8df2 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/bugprone-unhandled-exception-at-new.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/bugprone-unhandled-exception-at-new.rst
@@ -5,21 +5,51 @@ bugprone-unhandled-exception-at-new
 
 Finds calls to ``new`` with missing exception handler for ``std::bad_alloc``.
 
+Calls to ``new`` may throw exceptions of type ``std::bad_alloc`` that should
+be handled. Alternatively, the nonthrowing form of ``new`` can be
+used. The check verifies that the exception is handled in the function
+that calls ``new``.
+
+If a nonthrowing version is used or the exception is allowed to propagate out
+of the function no warning is generated.
+
+The exception handler is checked if it catches a ``std::bad_alloc`` or
+``std::exception`` exception type, or all exceptions (catch-all).
+The check assumes that any user-defined ``operator new`` is either
+``noexcept`` or may throw an exception of type ``std::bad_alloc`` (or one
+derived from it). Other exception class types are not taken into account.
+
 .. code-block:: c++
 
   int *f() noexcept {
-int *p = new int[1000];
+int *p = new int[1000]; // warning: missing exception handler for 
allocation failure at 'new'
+// ...
+return p;
+  }
+
+.. code-block:: c++
+
+  int *f1() { // not 'noexcept'
+int *p = new int[1000]; // no warning: exception can be handled outside
+// of this function
+// ...
+return p;
+  }
+
+  int *f2() noexcept {
+try {
+  int *p = new int[1000]; // no warning: exception is handled
+  // ...
+  return p;
+} catch (std::bad_alloc &) {
+  // ...
+}
+// ...
+  }
+
+  int *f3() noexcept {
+int *p = new (std::nothrow) int[1000]; // no warning: "nothrow" is used
 // ...
 return p;
   }
 
-Calls to ``new`` can throw exceptions of type ``std::bad_alloc`` that should
-be handled by the code. Alternatively, the nonthrowing form of ``new`` can be
-used. The check verifies that the exception is handled in the function
-that calls ``new``, unless a nonthrowing version is used or the exception
-is allowed to propagate out of the function (exception handler is checked for
-types ``std::bad_alloc``, ``std::exception``, and catch-all handler).
-The check assumes that any user-defined ``operator new`` is either
-``noexcept`` or may throw an exception of type ``std::bad_alloc`` (or derived
-from it). Other exception types or exceptions occurring in the object's
-constructor are not taken into account.



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


[PATCH] D115043: [clang][deps] Use MemoryBuffer in minimizing FS

2021-12-03 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added reviewers: Bigcheese, dexonsmith, arphaman.
jansvoboda11 requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

This patch avoids unnecessarily copying `mmap`-ed memory into 
`CachedFileSystemEntry` by storing `MemoryBuffer` instead. The change leads to 
~50% reduction of peak memory usage when scanning LLVM+Clang via 
`clang-scan-deps`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D115043

Files:
  clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
  clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
  llvm/include/llvm/Support/SmallVectorMemoryBuffer.h


Index: llvm/include/llvm/Support/SmallVectorMemoryBuffer.h
===
--- llvm/include/llvm/Support/SmallVectorMemoryBuffer.h
+++ llvm/include/llvm/Support/SmallVectorMemoryBuffer.h
@@ -14,6 +14,7 @@
 #ifndef LLVM_SUPPORT_SMALLVECTORMEMORYBUFFER_H
 #define LLVM_SUPPORT_SMALLVECTORMEMORYBUFFER_H
 
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/raw_ostream.h"
@@ -48,6 +49,16 @@
 init(this->SV.begin(), this->SV.end(), false);
   }
 
+  /// Construct a SmallVectorMemoryBuffer from the given SmallVector r-value,
+  /// and invoke the given function right after the move.
+  SmallVectorMemoryBuffer(
+  SmallVectorImpl &&SV,
+  llvm::function_ref &)> AfterMove)
+  : SV(std::move(SV)), BufferName("") {
+AfterMove(this->SV);
+init(this->SV.begin(), this->SV.end(), false);
+  }
+
   // Key function.
   ~SmallVectorMemoryBuffer() override;
 
Index: clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
===
--- clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
+++ clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
@@ -9,6 +9,7 @@
 #include "clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h"
 #include "clang/Lex/DependencyDirectivesSourceMinimizer.h"
 #include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/SmallVectorMemoryBuffer.h"
 #include "llvm/Support/Threading.h"
 
 using namespace clang;
@@ -43,11 +44,7 @@
 // FIXME: Propage the diagnostic if desired by the client.
 CachedFileSystemEntry Result;
 Result.MaybeStat = std::move(*Stat);
-Result.Contents.reserve(Buffer->getBufferSize() + 1);
-Result.Contents.append(Buffer->getBufferStart(), Buffer->getBufferEnd());
-// Implicitly null terminate the contents for Clang's lexer.
-Result.Contents.push_back('\0');
-Result.Contents.pop_back();
+Result.Contents = std::move(*MaybeBuffer);
 return Result;
   }
 
@@ -65,10 +62,12 @@
   // std::move will preserve it even if it needs to do a copy if the
   // SmallString still has the small capacity.
   MinimizedFileContents.push_back('\0');
-  Result.Contents = std::move(MinimizedFileContents);
-  // Now make the null terminator implicit again, so that Clang's lexer can 
find
-  // it right where the buffer ends.
-  Result.Contents.pop_back();
+  Result.Contents = std::make_unique(
+  std::move(MinimizedFileContents), [](SmallVectorImpl &SV) {
+// Now make the null terminator implicit again, so that Clang's lexer
+// can find it right where the buffer ends.
+SV.pop_back();
+  });
 
   // Compute the skipped PP ranges that speedup skipping over inactive
   // preprocessor blocks.
Index: 
clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
===
--- 
clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
+++ 
clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
@@ -65,7 +65,7 @@
   return MaybeStat.getError();
 assert(!MaybeStat->isDirectory() && "not a file");
 assert(isValid() && "not initialized");
-return Contents.str();
+return Contents->getBuffer();
   }
 
   /// \returns The error or the status of the entry.
@@ -94,11 +94,7 @@
 
 private:
   llvm::ErrorOr MaybeStat;
-  // Store the contents in a small string to allow a
-  // move from the small string for the minimized contents.
-  // Note: small size of 1 allows us to store an empty string with an implicit
-  // null terminator without any allocations.
-  llvm::SmallString<1> Contents;
+  std::unique_ptr Contents;
   PreprocessorSkippedRangeMapping PPSkippedRangeMapping;
 };
 


Index: llvm/include/llvm/Support/SmallVectorMemoryBuffer.h
===
--- llvm/include/llvm/Support/SmallVectorMemoryBuffer.h
+++ llvm/include/llvm/Support/SmallVectorMemoryBuffer.h
@@ -14,6 +14,7 @@
 #ifndef LLVM_SUPPORT_SMALLVECTORMEMORYBUFFER_H
 #define LLVM_SUPPORT_SMALLVECTO

[PATCH] D115043: [clang][deps] Use MemoryBuffer in minimizing FS

2021-12-03 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added inline comments.



Comment at: llvm/include/llvm/Support/SmallVectorMemoryBuffer.h:54
+  /// and invoke the given function right after the move.
+  SmallVectorMemoryBuffer(
+  SmallVectorImpl &&SV,

I'm not happy with introducing new (hacky) constructor.

But, the best alternative I could come up with is to avoid using 
`SmallVectorMemoryBuffer`, store the `SmallString` with minimized contents 
somewhere in the filesystem and refer to it via regular `MemoryBuffer`. This 
seems needlessly complicated, so hacky constructor it is...

Side question: is the hassle with implicit null-termination (expected by 
Clang's lexer) worth the complications? What are the benefits anyway?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115043

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


[PATCH] D115045: [Clang] Ignore CLANG_DEFAULT_LINKER for custom-linker toolchains

2021-12-03 Thread Simon Moll via Phabricator via cfe-commits
simoll created this revision.
simoll added reviewers: kaz7, MaskRay, phosek.
simoll requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Before, the CLANG_DEFAULT_LINKER cmake option was a global override for
the linker that shall be used on all toolchains.  The linker binary
specified that way may not be available on toolchains with custom
linkers. Eg, the only linker for VE is named 'nld' - any other linker
invalidates the toolchain.

  

This patch removes the hard override and instead lets the generic
toolchain implementation default to CLANG_DEFAULT_LINKER.  Toolchains
can now deviate with a custom linker name or deliberatly default to
CLANG_DEFAULT_LINKER.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D115045

Files:
  clang/include/clang/Driver/ToolChain.h
  clang/lib/Driver/ToolChain.cpp
  clang/test/Driver/ve-toolchain.c
  clang/test/Driver/ve-toolchain.cpp


Index: clang/test/Driver/ve-toolchain.cpp
===
--- clang/test/Driver/ve-toolchain.cpp
+++ clang/test/Driver/ve-toolchain.cpp
@@ -92,10 +92,10 @@
 /// Checking -fintegrated-as
 
 // RUN: %clangxx -### -target ve \
-// RUN:-x assembler -fuse-ld=ld %s 2>&1 | \
+// RUN:-x assembler %s 2>&1 | \
 // RUN:FileCheck -check-prefix=AS %s
 // RUN: %clangxx -### -target ve \
-// RUN:-fno-integrated-as -x assembler -fuse-ld=ld %s 2>&1 | \
+// RUN:-fno-integrated-as -x assembler %s 2>&1 | \
 // RUN:FileCheck -check-prefix=NAS %s
 
 // AS: clang{{.*}} "-cc1as"
@@ -113,7 +113,6 @@
 
 // RUN: %clangxx -### -target ve-unknown-linux-gnu \
 // RUN: --sysroot %S/Inputs/basic_ve_tree \
-// RUN: -fuse-ld=ld \
 // RUN: -resource-dir=%S/Inputs/basic_ve_tree/resource_dir \
 // RUN: --stdlib=c++ %s 2>&1 | FileCheck -check-prefix=DEF %s
 
Index: clang/test/Driver/ve-toolchain.c
===
--- clang/test/Driver/ve-toolchain.c
+++ clang/test/Driver/ve-toolchain.c
@@ -61,10 +61,10 @@
 /// Checking -fintegrated-as
 
 // RUN: %clang -### -target ve \
-// RUN:-x assembler -fuse-ld=ld %s 2>&1 | \
+// RUN:-x assembler %s 2>&1 | \
 // RUN:FileCheck -check-prefix=AS %s
 // RUN: %clang -### -target ve \
-// RUN:-fno-integrated-as -fuse-ld=ld -x assembler %s 2>&1 | \
+// RUN:-fno-integrated-as -x assembler %s 2>&1 | \
 // RUN:FileCheck -check-prefix=NAS %s
 
 // AS: clang{{.*}} "-cc1as"
@@ -83,7 +83,6 @@
 // RUN: %clang -### -target ve-unknown-linux-gnu \
 // RUN: --sysroot %S/Inputs/basic_ve_tree \
 // RUN: -resource-dir=%S/Inputs/basic_ve_tree/resource_dir \
-// RUN: -fuse-ld=ld \
 // RUN: %s 2>&1 | FileCheck -check-prefix=DEF %s
 
 // DEF:  clang{{.*}}" "-cc1"
Index: clang/lib/Driver/ToolChain.cpp
===
--- clang/lib/Driver/ToolChain.cpp
+++ clang/lib/Driver/ToolChain.cpp
@@ -541,6 +541,12 @@
   return D.GetProgramPath(Name, *this);
 }
 
+const char *ToolChain::getDefaultLinker() const {
+  if (StringRef(CLANG_DEFAULT_LINKER).empty())
+return "ld";
+  return CLANG_DEFAULT_LINKER;
+}
+
 std::string ToolChain::GetLinkerPath(bool *LinkerIsLLD) const {
   if (LinkerIsLLD)
 *LinkerIsLLD = false;
@@ -548,7 +554,7 @@
   // Get -fuse-ld= first to prevent -Wunused-command-line-argument. -fuse-ld= 
is
   // considered as the linker flavor, e.g. "bfd", "gold", or "lld".
   const Arg* A = Args.getLastArg(options::OPT_fuse_ld_EQ);
-  StringRef UseLinker = A ? A->getValue() : CLANG_DEFAULT_LINKER;
+  StringRef UseLinker = A ? A->getValue() : "";
 
   // --ld-path= takes precedence over -fuse-ld= and specifies the executable
   // name. -B, COMPILER_PATH and PATH and consulted if the value does not
Index: clang/include/clang/Driver/ToolChain.h
===
--- clang/include/clang/Driver/ToolChain.h
+++ clang/include/clang/Driver/ToolChain.h
@@ -420,7 +420,7 @@
   }
 
   /// GetDefaultLinker - Get the default linker to use.
-  virtual const char *getDefaultLinker() const { return "ld"; }
+  virtual const char *getDefaultLinker() const;
 
   /// GetDefaultRuntimeLibType - Get the default runtime library variant to 
use.
   virtual RuntimeLibType GetDefaultRuntimeLibType() const {


Index: clang/test/Driver/ve-toolchain.cpp
===
--- clang/test/Driver/ve-toolchain.cpp
+++ clang/test/Driver/ve-toolchain.cpp
@@ -92,10 +92,10 @@
 /// Checking -fintegrated-as
 
 // RUN: %clangxx -### -target ve \
-// RUN:-x assembler -fuse-ld=ld %s 2>&1 | \
+// RUN:-x assembler %s 2>&1 | \
 // RUN:FileCheck -check-prefix=AS %s
 // RUN: %clangxx -### -target ve \
-// RUN:-fno-integrated-as -x assembler -fuse-ld=ld %s 2>&1 | \
+// RUN:-fno-integrated-as -x assembler %s 2>&1 | \
 // RUN:FileCheck -check-prefix=NAS %s
 
 // AS: clang{{.*}

[PATCH] D106585: Fix clang debug info irgen of i128 enums

2021-12-03 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a subscriber: aeubanks.
rnk added a comment.

Thanks for the reduction, it sounds like there is something wrong with the way 
DIEnumerator is uniqued in the LLVMContext. I probably don't have time to 
follow up on this, but maybe @dblaikie and @aeubanks can help out.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106585

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


[PATCH] D106585: Fix clang debug info irgen of i128 enums

2021-12-03 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

This usage of isSameValue seems suspicious: 
https://github.com/llvm/llvm-project/blob/main/llvm/lib/IR/LLVMContextImpl.h#L389

It seems to allow the possibility that APInts of differing bitwidth compare 
equal, but the hash value incorporates the bitwidth, so they may be inserted 
into differing hash buckets.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106585

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


[clang] 7b54de5 - [funcattrs] Fix a bug in recently introduced writeonly argument inference

2021-12-03 Thread Philip Reames via cfe-commits

Author: Philip Reames
Date: 2021-12-03T08:57:15-08:00
New Revision: 7b54de5feffedfc08e5a02d6c9e27c54e3b7f119

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

LOG: [funcattrs] Fix a bug in recently introduced writeonly argument inference

This fixes a bug in 740057d.  There's two ways to describe the issue:
* One caller hasn't yet proven nocapture on the argument.  Given that, the 
inference routine is responsible for bailing out on a potential capture.
* Even if we know the argument is nocapture, the access inference needs to 
traverse the exact set of users the capture tracking would (or exit 
conservatively).  Even if capture tracking can prove a store is non-capturing 
(e.g. to a local alloc which doesn't escape), we still need to track the copy 
of the pointer to see if it's later reloaded and accessed again.

Note that all the test changes except the newly added ones appear to be false 
negatives.  That is, cases where we could prove writeonly, but the current code 
isn't strong enough.  That's why I didn't spot this originally.

Added: 


Modified: 
clang/test/CodeGen/ms-mixed-ptr-sizes.c
llvm/lib/Transforms/IPO/FunctionAttrs.cpp
llvm/test/Feature/OperandBundles/pr26510.ll
llvm/test/Transforms/Coroutines/coro-async.ll
llvm/test/Transforms/FunctionAttrs/2009-01-02-LocalStores.ll
llvm/test/Transforms/FunctionAttrs/nocapture.ll
llvm/test/Transforms/FunctionAttrs/readattrs.ll
llvm/test/Transforms/FunctionAttrs/writeonly.ll

Removed: 




diff  --git a/clang/test/CodeGen/ms-mixed-ptr-sizes.c 
b/clang/test/CodeGen/ms-mixed-ptr-sizes.c
index 294a8910e13e3..ececa42a4c4dd 100644
--- a/clang/test/CodeGen/ms-mixed-ptr-sizes.c
+++ b/clang/test/CodeGen/ms-mixed-ptr-sizes.c
@@ -7,32 +7,32 @@ struct Foo {
 };
 void use_foo(struct Foo *f);
 void test_sign_ext(struct Foo *f, int * __ptr32 __sptr i) {
-// X64-LABEL: define dso_local void @test_sign_ext({{.*}}i32 addrspace(270)* 
writeonly %i)
-// X86-LABEL: define dso_local void @test_sign_ext(%struct.Foo* %f, i32* 
writeonly %i)
+// X64-LABEL: define dso_local void @test_sign_ext({{.*}}i32 addrspace(270)* 
%i)
+// X86-LABEL: define dso_local void @test_sign_ext(%struct.Foo* %f, i32* %i)
 // X64: %{{.+}} = addrspacecast i32 addrspace(270)* %i to i32*
 // X86: %{{.+}} = addrspacecast i32* %i to i32 addrspace(272)*
   f->p64 = i;
   use_foo(f);
 }
 void test_zero_ext(struct Foo *f, int * __ptr32 __uptr i) {
-// X64-LABEL: define dso_local void @test_zero_ext({{.*}}i32 addrspace(271)* 
writeonly %i)
-// X86-LABEL: define dso_local void @test_zero_ext({{.*}}i32 addrspace(271)* 
writeonly %i)
+// X64-LABEL: define dso_local void @test_zero_ext({{.*}}i32 addrspace(271)* 
%i)
+// X86-LABEL: define dso_local void @test_zero_ext({{.*}}i32 addrspace(271)* 
%i)
 // X64: %{{.+}} = addrspacecast i32 addrspace(271)* %i to i32*
 // X86: %{{.+}} = addrspacecast i32 addrspace(271)* %i to i32 addrspace(272)*
   f->p64 = i;
   use_foo(f);
 }
 void test_trunc(struct Foo *f, int * __ptr64 i) {
-// X64-LABEL: define dso_local void @test_trunc(%struct.Foo* %f, i32* 
writeonly %i)
-// X86-LABEL: define dso_local void @test_trunc({{.*}}i32 addrspace(272)* 
writeonly %i)
+// X64-LABEL: define dso_local void @test_trunc(%struct.Foo* %f, i32* %i)
+// X86-LABEL: define dso_local void @test_trunc({{.*}}i32 addrspace(272)* %i)
 // X64: %{{.+}} = addrspacecast i32* %i to i32 addrspace(270)*
 // X86: %{{.+}} = addrspacecast i32 addrspace(272)* %i to i32*
   f->p32 = i;
   use_foo(f);
 }
 void test_noop(struct Foo *f, int * __ptr32 i) {
-// X64-LABEL: define dso_local void @test_noop({{.*}}i32 addrspace(270)* 
writeonly %i)
-// X86-LABEL: define dso_local void @test_noop({{.*}}i32* writeonly %i)
+// X64-LABEL: define dso_local void @test_noop({{.*}}i32 addrspace(270)* %i)
+// X86-LABEL: define dso_local void @test_noop({{.*}}i32* %i)
 // X64-NOT: addrspacecast
 // X86-NOT: addrspacecast
   f->p32 = i;
@@ -40,8 +40,8 @@ void test_noop(struct Foo *f, int * __ptr32 i) {
 }
 
 void test_other(struct Foo *f, __attribute__((address_space(10))) int *i) {
-// X64-LABEL: define dso_local void @test_other({{.*}}i32 addrspace(10)* 
writeonly %i)
-// X86-LABEL: define dso_local void @test_other({{.*}}i32 addrspace(10)* 
writeonly %i)
+// X64-LABEL: define dso_local void @test_other({{.*}}i32 addrspace(10)* %i)
+// X86-LABEL: define dso_local void @test_other({{.*}}i32 addrspace(10)* %i)
 // X64: %{{.+}} = addrspacecast i32 addrspace(10)* %i to i32 addrspace(270)*
 // X86: %{{.+}} = addrspacecast i32 addrspace(10)* %i to i32*
   f->p32 = (int * __ptr32)i;

diff  --git a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp 
b/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
index 1ad0055b56382..2cee9c0b4766a 100644
--- a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
+++ b/llvm/li

[PATCH] D115049: Fall back on Android triple w/o API level for runtimes search

2021-12-03 Thread Collin Baker via Phabricator via cfe-commits
collinbaker created this revision.
Herald added subscribers: abrachet, danielkiss, kristof.beyls.
collinbaker requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Clang searches for runtimes (e.g. libclang_rt*) first in a
subdirectory named for the target triple (corresponding to
LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON), then if it's not found uses
.../lib//libclang_rt* with a suffix corresponding to the arch and
environment name.

Android triples optionally include an API level indicating the minimum
Android version to be run on
(e.g. aarch64-unknown-linux-android21). When compiler-rt is built with
LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON this API level is part of the
output path.

Linking code built for a later API level against a runtime built for
an earlier one is safe. In projects with several API level targets
this is desireable to avoid re-building the same runtimes many
times. This is difficult with the current runtime search method: if
the API levels don't exactly match Clang gives up on the per-target
runtime directory path.

To enable this more simply, this change tries target triple without
the API level before falling back on the old layout.

Another option would be to try every API level in the triple,
e.g. check aarch-64-unknown-linux-android21, then ...20, then ...19,
etc.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D115049

Files:
  clang/include/clang/Driver/ToolChain.h
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChain.cpp
  clang/lib/Driver/ToolChains/Fuchsia.cpp
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/aarch64-unknown-linux-android/.keep
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/aarch64-unknown-linux-android/libclang_rt.builtins.a
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/aarch64-unknown-linux-android21/.keep
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/aarch64-unknown-linux-android21/libclang_rt.builtins.a
  clang/test/Driver/linux-per-target-runtime-dir.c

Index: clang/test/Driver/linux-per-target-runtime-dir.c
===
--- clang/test/Driver/linux-per-target-runtime-dir.c
+++ clang/test/Driver/linux-per-target-runtime-dir.c
@@ -25,3 +25,21 @@
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
 // RUN:   | FileCheck --check-prefix=CHECK-FILE-NAME-X8664 %s
 // CHECK-FILE-NAME-X8664: lib{{/|\\}}x86_64-unknown-linux-gnu{{/|\\}}libclang_rt.builtins.a
+
+// RUN: %clang -rtlib=compiler-rt -print-file-name=libclang_rt.builtins.a 2>&1 \
+// RUN: --target=aarch64-unknown-linux-android21 \
+// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
+// RUN:   | FileCheck --check-prefix=CHECK-FILE-NAME-ANDROID21 %s
+// CHECK-FILE-NAME-ANDROID21: lib{{/|\\}}aarch64-unknown-linux-android21{{/|\\}}libclang_rt.builtins.a
+
+// RUN: %clang -rtlib=compiler-rt -print-file-name=libclang_rt.builtins.a 2>&1 \
+// RUN: --target=aarch64-unknown-linux-android23 \
+// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
+// RUN:   | FileCheck --check-prefix=CHECK-FILE-NAME-ANDROID23 %s
+// CHECK-FILE-NAME-ANDROID23: lib{{/|\\}}aarch64-unknown-linux-android{{/|\\}}libclang_rt.builtins.a
+
+// RUN: %clang -rtlib=compiler-rt -print-file-name=libclang_rt.builtins.a 2>&1 \
+// RUN: --target=aarch64-unknown-linux-android \
+// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
+// RUN:   | FileCheck --check-prefix=CHECK-FILE-NAME-ANDROID %s
+// CHECK-FILE-NAME-ANDROID: lib{{/|\\}}aarch64-unknown-linux-android{{/|\\}}libclang_rt.builtins.a
Index: clang/lib/Driver/ToolChains/Fuchsia.cpp
===
--- clang/lib/Driver/ToolChains/Fuchsia.cpp
+++ clang/lib/Driver/ToolChains/Fuchsia.cpp
@@ -191,9 +191,11 @@
 
   auto FilePaths = [&](const Multilib &M) -> std::vector {
 std::vector FP;
-SmallString<128> P(getStdlibPath());
-llvm::sys::path::append(P, M.gccSuffix());
-FP.push_back(std::string(P.str()));
+for (const std::string &Path : getStdlibPaths()) {
+  SmallString<128> P(Path);
+  llvm::sys::path::append(P, M.gccSuffix());
+  FP.push_back(std::string(P.str()));
+}
 return FP;
   };
 
Index: clang/lib/Driver/ToolChain.cpp
===
--- clang/lib/Driver/ToolChain.cpp
+++ clang/lib/Driver/ToolChain.cpp
@@ -75,17 +75,16 @@
  const ArgList &Args)
 : D(D), Triple(T), Args(Args), CachedRTTIArg(GetRTTIArgument(Args)),
   CachedRTTIMode(CalculateRTTIMode(Args, Triple, CachedRTTIArg)) {
-  std::string RuntimePath = getRuntimePath();
-  if (getVFS().exists(RuntimePath))
-getLibraryPaths().push_back(RuntimePath);
-
-  std::string StdlibPath = getStdlibPath();
-  if (getVFS().exists(StdlibPath))
-getFilePaths().push_bac

[PATCH] D113294: [IR] Remove unbounded as possible value for vscale_range minimum

2021-12-03 Thread Paul Walker via Phabricator via cfe-commits
paulwalker-arm requested changes to this revision.
paulwalker-arm added inline comments.
This revision now requires changes to proceed.



Comment at: clang/lib/Basic/Targets/AArch64.cpp:476-484
+  assert(LangOpts.VScaleMin && "vscale min must be greater than 0!");
+
+  if (LangOpts.VScaleMax)
 return std::pair(LangOpts.VScaleMin,
  LangOpts.VScaleMax);
+
   if (hasFeature("sve"))

This looks like a change of behaviour to me.  Previously the command line flags 
would override the "sve" default but now that only happens when the user 
specifies a maximum value.  That means the interface can no longer be used to 
force truly width agnostic values.


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

https://reviews.llvm.org/D113294

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


[PATCH] D109818: [HIPSPV] Convert HIP kernels to SPIR-V kernels

2021-12-03 Thread Alexey Bader via Phabricator via cfe-commits
bader added a comment.

In D109818#3169531 , @linjamaki wrote:

> The patch is ready to land. @Anastasia, @bader, could you commit this patch 
> to the LLVM for us? Thanks.

Could you rebase on the tip of the main branch, please? I see a couple of 
conflicts when I cherry-pick the patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109818

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


[PATCH] D115049: Fall back on Android triple w/o API level for runtimes search

2021-12-03 Thread Collin Baker via Phabricator via cfe-commits
collinbaker updated this revision to Diff 391661.
collinbaker added a comment.

Fix variable name style


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115049

Files:
  clang/include/clang/Driver/ToolChain.h
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChain.cpp
  clang/lib/Driver/ToolChains/Fuchsia.cpp
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/aarch64-unknown-linux-android/.keep
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/aarch64-unknown-linux-android/libclang_rt.builtins.a
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/aarch64-unknown-linux-android21/.keep
  
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/aarch64-unknown-linux-android21/libclang_rt.builtins.a
  clang/test/Driver/linux-per-target-runtime-dir.c

Index: clang/test/Driver/linux-per-target-runtime-dir.c
===
--- clang/test/Driver/linux-per-target-runtime-dir.c
+++ clang/test/Driver/linux-per-target-runtime-dir.c
@@ -25,3 +25,21 @@
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
 // RUN:   | FileCheck --check-prefix=CHECK-FILE-NAME-X8664 %s
 // CHECK-FILE-NAME-X8664: lib{{/|\\}}x86_64-unknown-linux-gnu{{/|\\}}libclang_rt.builtins.a
+
+// RUN: %clang -rtlib=compiler-rt -print-file-name=libclang_rt.builtins.a 2>&1 \
+// RUN: --target=aarch64-unknown-linux-android21 \
+// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
+// RUN:   | FileCheck --check-prefix=CHECK-FILE-NAME-ANDROID21 %s
+// CHECK-FILE-NAME-ANDROID21: lib{{/|\\}}aarch64-unknown-linux-android21{{/|\\}}libclang_rt.builtins.a
+
+// RUN: %clang -rtlib=compiler-rt -print-file-name=libclang_rt.builtins.a 2>&1 \
+// RUN: --target=aarch64-unknown-linux-android23 \
+// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
+// RUN:   | FileCheck --check-prefix=CHECK-FILE-NAME-ANDROID23 %s
+// CHECK-FILE-NAME-ANDROID23: lib{{/|\\}}aarch64-unknown-linux-android{{/|\\}}libclang_rt.builtins.a
+
+// RUN: %clang -rtlib=compiler-rt -print-file-name=libclang_rt.builtins.a 2>&1 \
+// RUN: --target=aarch64-unknown-linux-android \
+// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
+// RUN:   | FileCheck --check-prefix=CHECK-FILE-NAME-ANDROID %s
+// CHECK-FILE-NAME-ANDROID: lib{{/|\\}}aarch64-unknown-linux-android{{/|\\}}libclang_rt.builtins.a
Index: clang/lib/Driver/ToolChains/Fuchsia.cpp
===
--- clang/lib/Driver/ToolChains/Fuchsia.cpp
+++ clang/lib/Driver/ToolChains/Fuchsia.cpp
@@ -191,9 +191,11 @@
 
   auto FilePaths = [&](const Multilib &M) -> std::vector {
 std::vector FP;
-SmallString<128> P(getStdlibPath());
-llvm::sys::path::append(P, M.gccSuffix());
-FP.push_back(std::string(P.str()));
+for (const std::string &Path : getStdlibPaths()) {
+  SmallString<128> P(Path);
+  llvm::sys::path::append(P, M.gccSuffix());
+  FP.push_back(std::string(P.str()));
+}
 return FP;
   };
 
Index: clang/lib/Driver/ToolChain.cpp
===
--- clang/lib/Driver/ToolChain.cpp
+++ clang/lib/Driver/ToolChain.cpp
@@ -75,17 +75,16 @@
  const ArgList &Args)
 : D(D), Triple(T), Args(Args), CachedRTTIArg(GetRTTIArgument(Args)),
   CachedRTTIMode(CalculateRTTIMode(Args, Triple, CachedRTTIArg)) {
-  std::string RuntimePath = getRuntimePath();
-  if (getVFS().exists(RuntimePath))
-getLibraryPaths().push_back(RuntimePath);
-
-  std::string StdlibPath = getStdlibPath();
-  if (getVFS().exists(StdlibPath))
-getFilePaths().push_back(StdlibPath);
+  auto addIfExists = [this](path_list &List, const std::string &Path) {
+if (getVFS().exists(Path))
+  List.push_back(Path);
+  };
 
-  std::string CandidateLibPath = getArchSpecificLibPath();
-  if (getVFS().exists(CandidateLibPath))
-getFilePaths().push_back(CandidateLibPath);
+  for (const auto &Path : getRuntimePaths())
+addIfExists(getLibraryPaths(), Path);
+  for (const auto &Path : getStdlibPaths())
+addIfExists(getFilePaths(), Path);
+  addIfExists(getFilePaths(), getArchSpecificLibPath());
 }
 
 void ToolChain::setTripleEnvironment(llvm::Triple::EnvironmentType Env) {
@@ -485,16 +484,36 @@
   return Args.MakeArgString(getCompilerRT(Args, Component, Type));
 }
 
-std::string ToolChain::getRuntimePath() const {
-  SmallString<128> P(D.ResourceDir);
-  llvm::sys::path::append(P, "lib", getTripleString());
-  return std::string(P.str());
+ToolChain::path_list ToolChain::getRuntimePaths() const {
+  path_list Paths;
+  auto addPathForTriple = [this, &Paths](const llvm::Triple &Triple) {
+SmallString<128> P(D.ResourceDir);
+llvm::sys::path::append(P, "lib", Triple.str());
+Paths.push_back(std::string(P.str()));
+  };
+

[PATCH] D113294: [IR] Remove unbounded as possible value for vscale_range minimum

2021-12-03 Thread Cullen Rhodes via Phabricator via cfe-commits
c-rhodes added inline comments.



Comment at: clang/lib/Basic/Targets/AArch64.cpp:476-484
+  assert(LangOpts.VScaleMin && "vscale min must be greater than 0!");
+
+  if (LangOpts.VScaleMax)
 return std::pair(LangOpts.VScaleMin,
  LangOpts.VScaleMax);
+
   if (hasFeature("sve"))

paulwalker-arm wrote:
> This looks like a change of behaviour to me.  Previously the command line 
> flags would override the "sve" default but now that only happens when the 
> user specifies a maximum value.  That means the interface can no longer be 
> used to force truly width agnostic values.
> This looks like a change of behaviour to me.  Previously the command line 
> flags would override the "sve" default but now that only happens when the 
> user specifies a maximum value.  That means the interface can no longer be 
> used to force truly width agnostic values.

I think the issue here is the default of 1 for min would always trigger `if 
(LangOpts.VScaleMin || LangOpts.VScaleMax)` overriding the SVE default. Perhaps 
the default can be removed from the driver option and handled here, i.e.

```
if (LangOpts.VScaleMin || LangOpts.VScaleMax)
return std::pair(LangOpts.VScaleMin ? 
LangOpts.VScaleMin : 1,
 LangOpts.VScaleMax);
```




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

https://reviews.llvm.org/D113294

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


[PATCH] D113294: [IR] Remove unbounded as possible value for vscale_range minimum

2021-12-03 Thread Paul Walker via Phabricator via cfe-commits
paulwalker-arm added a comment.

I agree, it's the change to VScaleMin that has caused the issue.  If the 
LangOpts default can remain as 0 and you can still achieve what you're after 
then that would be perfect.


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

https://reviews.llvm.org/D113294

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


[PATCH] D115050: [clang-format] PR48916 PointerAlignment not working when using C++20 init-statement in for loop

2021-12-03 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay created this revision.
MyDeveloperDay added reviewers: HazardyKnusperkeks, curdeius.
MyDeveloperDay added projects: clang, clang-format.
MyDeveloperDay requested review of this revision.

https://bugs.llvm.org/show_bug.cgi?id=48916

Left and Right Alignment inside a loop is misaligned.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D115050

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -1924,6 +1924,7 @@
   verifyFormat("int *a = f1();", Style);
   verifyFormat("int &b = f2();", Style);
   verifyFormat("int &&c = f3();", Style);
+  verifyFormat("for (auto a = 0, b = 0; const auto &c : {1, 2, 3})", Style);
 
   Style.AlignConsecutiveDeclarations = FormatStyle::ACS_Consecutive;
   verifyFormat("Const unsigned int *c;\n"
@@ -1943,6 +1944,7 @@
   verifyFormat("int* a = f1();", Style);
   verifyFormat("int& b = f2();", Style);
   verifyFormat("int&& c = f3();", Style);
+  verifyFormat("for (auto a = 0, b = 0; const auto& c : {1, 2, 3})", Style);
 
   Style.AlignConsecutiveDeclarations = FormatStyle::ACS_Consecutive;
   verifyFormat("Const unsigned int* c;\n"
@@ -1979,6 +1981,7 @@
   verifyFormat("int* a = f1();", Style);
   verifyFormat("int & b = f2();", Style);
   verifyFormat("int && c = f3();", Style);
+  verifyFormat("for (auto a = 0, b = 0; const auto & c : {1, 2, 3})", Style);
 
   Style.AlignConsecutiveDeclarations = FormatStyle::ACS_Consecutive;
   verifyFormat("Const unsigned int*  c;\n"
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3024,8 +3024,12 @@
  Style.SpaceAroundPointerQualifiers == FormatStyle::SAPQ_Both) &&
 (Left.is(TT_AttributeParen) || 
Left.canBePointerOrReferenceQualifier()))
   return true;
+if (Left.Tok.isLiteral())
+  return true;
+if (Left.Tok.is(tok::kw_auto))
+  return getTokenPointerOrReferenceAlignment(Right) !=
+ FormatStyle::PAS_Left;
 return (
-Left.Tok.isLiteral() ||
 (!Left.isOneOf(TT_PointerOrReference, tok::l_paren) &&
  (getTokenPointerOrReferenceAlignment(Right) != FormatStyle::PAS_Left 
||
   (Line.IsMultiVariableDeclStmt &&
@@ -3044,18 +3048,32 @@
  Style.SpaceAroundPointerQualifiers == FormatStyle::SAPQ_Both) &&
 Right.canBePointerOrReferenceQualifier())
   return true;
-return Right.Tok.isLiteral() || Right.is(TT_BlockComment) ||
-   (Right.isOneOf(Keywords.kw_override, Keywords.kw_final) &&
-!Right.is(TT_StartOfName)) ||
-   (Right.is(tok::l_brace) && Right.is(BK_Block)) ||
-   (!Right.isOneOf(TT_PointerOrReference, TT_ArraySubscriptLSquare,
-   tok::l_paren) &&
-(getTokenPointerOrReferenceAlignment(Left) !=
- FormatStyle::PAS_Right &&
- !Line.IsMultiVariableDeclStmt) &&
-Left.Previous &&
-!Left.Previous->isOneOf(tok::l_paren, tok::coloncolon,
-tok::l_square));
+// & 1
+if (Right.Tok.isLiteral())
+  return true;
+// & // comment
+if (Right.is(TT_BlockComment))
+  return true;
+// foo() -> const Bar * override/final
+if (Right.isOneOf(Keywords.kw_override, Keywords.kw_final) &&
+!Right.is(TT_StartOfName))
+  return true;
+// & {
+if (Right.is(tok::l_brace) && Right.is(BK_Block))
+  return true;
+// for (auto a = 0, b = 0; const auto& c : {1, 2, 3})
+if (Left.Previous && Left.Previous->is(tok::kw_auto) &&
+Right.is(tok::identifier))
+  return getTokenPointerOrReferenceAlignment(Left) !=
+ FormatStyle::PAS_Right;
+
+return (
+!Right.isOneOf(TT_PointerOrReference, TT_ArraySubscriptLSquare,
+   tok::l_paren) &&
+(getTokenPointerOrReferenceAlignment(Left) != FormatStyle::PAS_Right &&
+ !Line.IsMultiVariableDeclStmt) &&
+Left.Previous &&
+!Left.Previous->isOneOf(tok::l_paren, tok::coloncolon, tok::l_square));
   }
   // Ensure right pointer alignment with ellipsis e.g. int *...P
   if (Left.is(tok::ellipsis) && Left.Previous &&


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -1924,6 +1924,7 @@
   verifyFormat("int *a = f1();", Style);
   verifyFormat("int &b = f2();", Style);
   verifyFormat("int &&c = f3();", Style);
+  verifyFormat("for (auto a = 0, b = 0; const auto &c : {1, 2, 3})", Style);
 
   Style.AlignConsecutiveDeclarations = FormatStyle::ACS_Consecutive;
   verifyFormat("Const unsig

[PATCH] D106585: Fix clang debug info irgen of i128 enums

2021-12-03 Thread Arthur Eubanks via Phabricator via cfe-commits
aeubanks added a comment.

In D106585#3169898 , @rnk wrote:

> This usage of isSameValue seems suspicious: 
> https://github.com/llvm/llvm-project/blob/main/llvm/lib/IR/LLVMContextImpl.h#L389
>
> It seems to allow the possibility that APInts of differing bitwidth compare 
> equal, but the hash value incorporates the bitwidth, so they may be inserted 
> into differing hash buckets.

yup, also checking the bit width makes the non-determinism go away, I'll send 
out a patch


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106585

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


[PATCH] D115032: [AMDGPU] Change llvm.amdgcn.image.bvh.intersect.ray to take vec3 args

2021-12-03 Thread Stanislav Mekhanoshin via Phabricator via cfe-commits
rampitec accepted this revision.
rampitec 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/D115032/new/

https://reviews.llvm.org/D115032

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


[PATCH] D115032: [AMDGPU] Change llvm.amdgcn.image.bvh.intersect.ray to take vec3 args

2021-12-03 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl accepted this revision.
yaxunl added a comment.

Ideally, we could let the builtins accept both vec3 and vec4. But I am OK with 
this for now. I think the overhead may be minimal.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115032

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


[PATCH] D115050: [clang-format] PR48916 PointerAlignment not working when using C++20 init-statement in for loop

2021-12-03 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added inline comments.



Comment at: clang/lib/Format/TokenAnnotator.cpp:3052
+// & 1
+if (Right.Tok.isLiteral())
+  return true;

Is this valid code? Or did we just wrongly assign PointerOrReference? I'd say 
after that there can not be a literal in valid code, thus we do not need to 
handle it.



Comment at: clang/lib/Format/TokenAnnotator.cpp:3065
+// for (auto a = 0, b = 0; const auto& c : {1, 2, 3})
+if (Left.Previous && Left.Previous->is(tok::kw_auto) &&
+Right.is(tok::identifier))

Do we need this just for `auto`? What when `auto` is replaced with `int`?



Comment at: clang/lib/Format/TokenAnnotator.cpp:3070
+
+return (
+!Right.isOneOf(TT_PointerOrReference, TT_ArraySubscriptLSquare,

Drop the outer paren?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115050

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


[PATCH] D99797: [analyzer] Implemented RangeSet::Factory::unite function to handle intersections and adjacency

2021-12-03 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov added a comment.

@martong

> Nice, assiduous work!

Many thanks for your time! Your work is not less assiduous!

> (LHS, RHS) swaps

it doesn't really matter, as the operation is comutative, but, yes, it does 
matter to depict the particular test case. I'll revise twise LHS-RHS's.

> I am going to continue with the next patch in the stack. I recognize that the 
> handling of casts is very important and problems related to not handling them 
> occurs even more frequently as other parts of the engine evolve (e.g. 
> https://reviews.llvm.org/D113753#3167134)

Aha. I saw you patch. I'll join to review it.




Comment at: clang/unittests/StaticAnalyzer/RangeSetTest.cpp:441
+  //___/__/_\__\___   ___/___\___
+  this->checkUnite({{MID, MID}}, {A, D}, {{A, D}});
+  this->checkUnite({{B, C}}, {A, D}, {{A, D}});

martong wrote:
> 
There are three overloads of `checkUnite` which correspond to three overloads 
of `RangeSet::unite`. I made it consistent to other check-functions (`add` 
e.g.).



Comment at: clang/unittests/StaticAnalyzer/RangeSetTest.cpp:449
+  //___/___\___   ___/___\___
+  this->checkUnite({{MIN, MIN}}, MIN, {{MIN, MIN}});
+  this->checkUnite({{A, B}}, {A, B}, {{A, B}});

martong wrote:
> I think, either we should use `{{X, X}}` or `X` everywhere, but not mixed. 
This tests different oveloaded versions of `RangeSet::unite`.



Comment at: clang/unittests/StaticAnalyzer/RangeSetTest.cpp:528-529
+  //_/__\_/__\_/\_/\_/\_   _/__\_/__\_/\_/\_/\_
+  this->checkUnite({{MIN, A}, {A + 2, B}}, {{MID, C}, {C + 2, D - 2}, {D, 
MAX}},
+   {{MIN, A}, {A + 2, B}, {MID, C}, {C + 2, D - 2}, {D, MAX}});
+  this->checkUnite({{MIN, MIN}, {A, A}}, {{B, B}, {C, C}, {MAX, MAX}},

martong wrote:
> I think we could better format these more complex cases.
clang-fromat acts on its own. But I agree, it looks the way better. I'll 
consider wrapping it into `// clang-format on/off` directives.



Comment at: clang/unittests/StaticAnalyzer/RangeSetTest.cpp:590-592
+  this->checkUnite({{A, B - 1}, {B + 1, C - 1}, {C + 2, D}, {MAX - 1, MAX}},
+   {{MIN, MIN}, {B, MID}, {MID + 1, C}, {C + 4, D - 1}},
+   {{MIN, MIN}, {A, C}, {C + 2, D}, {MAX - 1, MAX}});

martong wrote:
> martong wrote:
> > 
> What do you think about this format? The result can be easily verified this 
> way I think, but a bit ugly ...
I think ASCII art does this job. Let code look as code :)


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

https://reviews.llvm.org/D99797

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


[PATCH] D115003: [funcattrs] Infer writeonly argument attribute [part 2]

2021-12-03 Thread Philip Reames via Phabricator via cfe-commits
reames planned changes to this revision.
reames added a comment.

Has the same propagation bug fixed in 7b54de5f 
, need to 
rework.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115003

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


[PATCH] D115021: [funcatts] Rewrite callsite operand handling in memory access inference

2021-12-03 Thread Philip Reames via Phabricator via cfe-commits
reames planned changes to this revision.
reames added a comment.

Needs reworked over previous patch in stack.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115021

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


[PATCH] D115050: [clang-format] PR48916 PointerAlignment not working when using C++20 init-statement in for loop

2021-12-03 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added inline comments.



Comment at: clang/lib/Format/TokenAnnotator.cpp:3052
+// & 1
+if (Right.Tok.isLiteral())
+  return true;

HazardyKnusperkeks wrote:
> Is this valid code? Or did we just wrongly assign PointerOrReference? I'd say 
> after that there can not be a literal in valid code, thus we do not need to 
> handle it.
Ok so as you see I broken out the compound statement, to be honest I find these 
compound if's unreadable and I can't for the life of me work out what case they 
are trying to handle. (I want to do this more)..

Please no one say doing it separately is slower! without measuring it..we are 
talking ns difference if anything at all.

I agree I truly believe we are mis assigning PointerOrReference/BinaryOperator 
this as I mentioned  in
https://lists.llvm.org/pipermail/cfe-dev/2021-December/069486.html is a major 
issue and I think from time to time these rules try to correct that situation, 
in this case & is the logical operation on a reference.



Comment at: clang/lib/Format/TokenAnnotator.cpp:3065
+// for (auto a = 0, b = 0; const auto& c : {1, 2, 3})
+if (Left.Previous && Left.Previous->is(tok::kw_auto) &&
+Right.is(tok::identifier))

HazardyKnusperkeks wrote:
> Do we need this just for `auto`? What when `auto` is replaced with `int`?
Man! you right...duh how did I miss that...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115050

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


[PATCH] D113294: [IR] Remove unbounded as possible value for vscale_range minimum

2021-12-03 Thread Cullen Rhodes via Phabricator via cfe-commits
c-rhodes updated this revision to Diff 391668.
c-rhodes added a comment.

Revert to previous behaviour where both the min/max Clang flags override SVE.


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

https://reviews.llvm.org/D113294

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGen/arm-sve-vector-bits-vscale-range.c
  clang/test/Frontend/aarch64-vscale-min.c
  llvm/docs/LangRef.rst
  llvm/include/llvm/IR/Attributes.h
  llvm/lib/IR/Attributes.cpp
  llvm/lib/IR/Verifier.cpp
  llvm/test/Analysis/CostModel/AArch64/sve-gather.ll
  llvm/test/Analysis/CostModel/AArch64/sve-scatter.ll
  llvm/test/Bitcode/attributes.ll
  llvm/test/Transforms/InstCombine/icmp-vscale.ll
  llvm/test/Transforms/InstCombine/vscale_sext_and_zext.ll
  llvm/test/Transforms/InstCombine/vscale_trunc.ll
  llvm/test/Transforms/LoopVectorize/AArch64/first-order-recurrence.ll
  llvm/test/Transforms/LoopVectorize/AArch64/scalable-strict-fadd.ll
  llvm/test/Transforms/LoopVectorize/AArch64/scalable-vectorization.ll
  llvm/test/Transforms/LoopVectorize/AArch64/scalable-vf-hint.ll
  llvm/test/Transforms/LoopVectorize/AArch64/sve-cond-inv-loads.ll
  llvm/test/Transforms/LoopVectorize/AArch64/sve-gather-scatter.ll
  llvm/test/Transforms/LoopVectorize/AArch64/sve-inv-store.ll
  llvm/test/Transforms/LoopVectorize/AArch64/sve-large-strides.ll
  llvm/test/Transforms/LoopVectorize/AArch64/sve-strict-fadd-cost.ll
  llvm/test/Transforms/LoopVectorize/AArch64/sve-widen-phi.ll
  llvm/test/Verifier/vscale_range.ll

Index: llvm/test/Verifier/vscale_range.ll
===
--- llvm/test/Verifier/vscale_range.ll
+++ llvm/test/Verifier/vscale_range.ll
@@ -1,4 +1,7 @@
 ; RUN: not llvm-as %s -o /dev/null 2>&1 | FileCheck %s
 
+; CHECK: 'vscale_range' minimum must be greater than 0
+declare i8* @a(i32*) vscale_range(0, 1)
+
 ; CHECK: 'vscale_range' minimum cannot be greater than maximum
 declare i8* @b(i32*) vscale_range(8, 1)
Index: llvm/test/Transforms/LoopVectorize/AArch64/sve-widen-phi.ll
===
--- llvm/test/Transforms/LoopVectorize/AArch64/sve-widen-phi.ll
+++ llvm/test/Transforms/LoopVectorize/AArch64/sve-widen-phi.ll
@@ -175,7 +175,7 @@
   ret i32 %tmp5
 }
 
-attributes #0 = { vscale_range(0, 16) }
+attributes #0 = { vscale_range(1, 16) }
 !0 = distinct !{!0, !1, !2, !3, !4, !5}
 !1 = !{!"llvm.loop.mustprogress"}
 !2 = !{!"llvm.loop.vectorize.width", i32 4}
Index: llvm/test/Transforms/LoopVectorize/AArch64/sve-strict-fadd-cost.ll
===
--- llvm/test/Transforms/LoopVectorize/AArch64/sve-strict-fadd-cost.ll
+++ llvm/test/Transforms/LoopVectorize/AArch64/sve-strict-fadd-cost.ll
@@ -53,7 +53,7 @@
   ret double %add
 }
 
-attributes #0 = { "target-features"="+sve" vscale_range(0, 16) }
+attributes #0 = { "target-features"="+sve" vscale_range(1, 16) }
 
 !0 = distinct !{!0, !1}
 !1 = !{!"llvm.loop.vectorize.scalable.enable", i1 true}
Index: llvm/test/Transforms/LoopVectorize/AArch64/sve-large-strides.ll
===
--- llvm/test/Transforms/LoopVectorize/AArch64/sve-large-strides.ll
+++ llvm/test/Transforms/LoopVectorize/AArch64/sve-large-strides.ll
@@ -90,7 +90,7 @@
   ret void
 }
 
-attributes #0 = { vscale_range(0, 16) }
+attributes #0 = { vscale_range(1, 16) }
 !0 = distinct !{!0, !1, !2, !3, !4, !5}
 !1 = !{!"llvm.loop.mustprogress"}
 !2 = !{!"llvm.loop.vectorize.width", i32 4}
Index: llvm/test/Transforms/LoopVectorize/AArch64/sve-inv-store.ll
===
--- llvm/test/Transforms/LoopVectorize/AArch64/sve-inv-store.ll
+++ llvm/test/Transforms/LoopVectorize/AArch64/sve-inv-store.ll
@@ -59,7 +59,7 @@
   ret void
 }
 
-attributes #0 = { "target-features"="+neon,+sve" vscale_range(0, 16) }
+attributes #0 = { "target-features"="+neon,+sve" vscale_range(1, 16) }
 
 !0 = distinct !{!0, !1, !2, !3, !4, !5}
 !1 = !{!"llvm.loop.mustprogress"}
Index: llvm/test/Transforms/LoopVectorize/AArch64/sve-gather-scatter.ll
===
--- llvm/test/Transforms/LoopVectorize/AArch64/sve-gather-scatter.ll
+++ llvm/test/Transforms/LoopVectorize/AArch64/sve-gather-scatter.ll
@@ -153,7 +153,7 @@
   ret void
 }
 
-attributes #0 = { vscale_range(0, 16) }
+attributes #0 = { vscale_range(1, 16) }
 
 !0 = distinct !{!0, !1, !2, !3, !4, !5}
 !1 = !{!"llvm.loop.mustprogress"}
Index: llvm/test/Transforms/LoopVectorize/AArch64/sve-cond-inv-loads.ll
===
--- llvm/test/Transforms/LoopVectorize/AArch64/sve-cond-inv-loads.ll
+++ llvm/test/Transforms/LoopVectorize/AArch64/sve-cond-inv-lo

[PATCH] D113294: [IR] Remove unbounded as possible value for vscale_range minimum

2021-12-03 Thread Cullen Rhodes via Phabricator via cfe-commits
c-rhodes marked an inline comment as done.
c-rhodes added a comment.

In D113294#3170007 , @paulwalker-arm 
wrote:

> I agree, it's the change to VScaleMin that has caused the issue.  If the 
> LangOpts default can remain as 0 and you can still achieve what you're after 
> then that would be perfect.

Not sure why this was an issue when I first looked at it, fresh eyes maybe, 
fixed now. Thanks for raising.


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

https://reviews.llvm.org/D113294

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


[PATCH] D106585: Fix clang debug info irgen of i128 enums

2021-12-03 Thread Arthur Eubanks via Phabricator via cfe-commits
aeubanks added a comment.

In D106585#3170019 , @aeubanks wrote:

> In D106585#3169898 , @rnk wrote:
>
>> This usage of isSameValue seems suspicious: 
>> https://github.com/llvm/llvm-project/blob/main/llvm/lib/IR/LLVMContextImpl.h#L389
>>
>> It seems to allow the possibility that APInts of differing bitwidth compare 
>> equal, but the hash value incorporates the bitwidth, so they may be inserted 
>> into differing hash buckets.
>
> yup, also checking the bit width makes the non-determinism go away, I'll send 
> out a patch

https://reviews.llvm.org/D115054


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106585

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


[PATCH] D113917: Add infrastructure to support matcher names.

2021-12-03 Thread James King via Phabricator via cfe-commits
jcking1034 added a comment.

@hokein @aaron.ballman Following up on this, let me know if there are any other 
action items to address!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113917

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


[PATCH] D113294: [IR] Remove unbounded as possible value for vscale_range minimum

2021-12-03 Thread Paul Walker via Phabricator via cfe-commits
paulwalker-arm added inline comments.



Comment at: clang/lib/Basic/Targets/AArch64.cpp:476-484
+  assert(LangOpts.VScaleMin && "vscale min must be greater than 0!");
+
+  if (LangOpts.VScaleMax)
 return std::pair(LangOpts.VScaleMin,
  LangOpts.VScaleMax);
+
   if (hasFeature("sve"))

c-rhodes wrote:
> paulwalker-arm wrote:
> > This looks like a change of behaviour to me.  Previously the command line 
> > flags would override the "sve" default but now that only happens when the 
> > user specifies a maximum value.  That means the interface can no longer be 
> > used to force truly width agnostic values.
> > This looks like a change of behaviour to me.  Previously the command line 
> > flags would override the "sve" default but now that only happens when the 
> > user specifies a maximum value.  That means the interface can no longer be 
> > used to force truly width agnostic values.
> 
> I think the issue here is the default of 1 for min would always trigger `if 
> (LangOpts.VScaleMin || LangOpts.VScaleMax)` overriding the SVE default. 
> Perhaps the default can be removed from the driver option and handled here, 
> i.e.
> 
> ```
> if (LangOpts.VScaleMin || LangOpts.VScaleMax)
> return std::pair(LangOpts.VScaleMin ? 
> LangOpts.VScaleMin : 1,
>  LangOpts.VScaleMax);
> ```
> 
> 
Is this enough?  I'm not sure it'll work because `LangOpts.VScaleMin` defaults 
to 1 and thus you'll always end up passing the first check, unless the user 
specifically uses `-mvscale-min=0` which they cannot because that'll result in 
`diag::err_cc1_unbounded_vscale_min`.

Do we need to link the LangOpt defaults to the attribute defaults?  I'm think 
that having the LangOpts default to zero is a good way to represent "value is 
unspecified" with regards to the `LangOpts.VScaleMin`.


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

https://reviews.llvm.org/D113294

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


[libunwind] f178a05 - [libunwind] Fix unwind_leaffunction test

2021-12-03 Thread Leonard Chan via cfe-commits

Author: Leonard Chan
Date: 2021-12-03T11:21:20-08:00
New Revision: f178a05f220403f2a9d73c7640bfcc7dc2d7be72

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

LOG: [libunwind] Fix unwind_leaffunction test

It's possible for this test not to pass if the libc used does not provide
unwind info for raise. We can replace it with __builtin_cast, which can lead
to a SIGTRAP on x86_64 and a SIGILL on aarch64.

Using this alternative, a nop is needed before the __builtin_cast. This is
because libunwind incorrectly decrements pc, which can cause pc to jump into
the previous function and use the incorrect FDE.

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

Added: 


Modified: 
libunwind/test/unwind_leaffunction.pass.cpp

Removed: 




diff  --git a/libunwind/test/unwind_leaffunction.pass.cpp 
b/libunwind/test/unwind_leaffunction.pass.cpp
index 2a6d8311e24c7..8ff21dd35449c 100644
--- a/libunwind/test/unwind_leaffunction.pass.cpp
+++ b/libunwind/test/unwind_leaffunction.pass.cpp
@@ -39,11 +39,17 @@ void signal_handler(int signum) {
 }
 
 __attribute__((noinline)) void crashing_leaf_func(void) {
-  raise(SIGSEGV);
+  // libunwind searches for the address before the return address which points
+  // to the trap instruction. NOP guarantees the trap instruction is not the
+  // first instruction of the function.
+  // We should keep this here for other unwinders that also decrement pc.
+  __asm__ __volatile__("nop");
+  __builtin_trap();
 }
 
 int main(int, char**) {
-  signal(SIGSEGV, signal_handler);
+  signal(SIGTRAP, signal_handler);
+  signal(SIGILL, signal_handler);
   crashing_leaf_func();
   return -2;
 }



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


[PATCH] D115060: [clang-format][NFC] Code Tidies in UnwrappedLineFormatter

2021-12-03 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks created this revision.
HazardyKnusperkeks added reviewers: owenpan, MyDeveloperDay, curdeius.
HazardyKnusperkeks added a project: clang-format.
HazardyKnusperkeks requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

- Give I[1] a name:
  - Easier to understand
  - Easier to debug (since you don't go through operator[] everytime)
- TheLine->First != TheLine->Last follows since last is a l brace and first 
isn't.
- Factor the check for is(tok::l_brace) out.
- Drop else after return.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D115060

Files:
  clang/lib/Format/UnwrappedLineFormatter.cpp

Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -211,10 +211,11 @@
 const AnnotatedLine *TheLine = *I;
 if (TheLine->Last->is(TT_LineComment))
   return 0;
-if (I[1]->Type == LT_Invalid || I[1]->First->MustBreakBefore)
+const auto &NextLine = *I[1];
+if (NextLine.Type == LT_Invalid || NextLine.First->MustBreakBefore)
   return 0;
 if (TheLine->InPPDirective &&
-(!I[1]->InPPDirective || I[1]->First->HasUnescapedNewline))
+(!NextLine.InPPDirective || NextLine.First->HasUnescapedNewline))
   return 0;
 
 if (Style.ColumnLimit > 0 && Indent > Style.ColumnLimit)
@@ -231,13 +232,13 @@
 if (TheLine->Last->is(TT_FunctionLBrace) &&
 TheLine->First == TheLine->Last &&
 !Style.BraceWrapping.SplitEmptyFunction &&
-I[1]->First->is(tok::r_brace))
+NextLine.First->is(tok::r_brace))
   return tryMergeSimpleBlock(I, E, Limit);
 
 // Handle empty record blocks where the brace has already been wrapped
 if (TheLine->Last->is(tok::l_brace) && TheLine->First == TheLine->Last &&
 I != AnnotatedLines.begin()) {
-  bool EmptyBlock = I[1]->First->is(tok::r_brace);
+  bool EmptyBlock = NextLine.First->is(tok::r_brace);
 
   const FormatToken *Tok = I[-1]->First;
   if (Tok && Tok->is(tok::comment))
@@ -267,7 +268,7 @@
 bool MergeShortFunctions =
 Style.AllowShortFunctionsOnASingleLine == FormatStyle::SFS_All ||
 (Style.AllowShortFunctionsOnASingleLine >= FormatStyle::SFS_Empty &&
- I[1]->First->is(tok::r_brace)) ||
+ NextLine.First->is(tok::r_brace)) ||
 (Style.AllowShortFunctionsOnASingleLine & FormatStyle::SFS_InlineOnly &&
  TheLine->Level != 0);
 
@@ -312,48 +313,49 @@
   return MergeShortFunctions ? tryMergeSimpleBlock(I, E, Limit) : 0;
 }
 // Try to merge a control statement block with left brace unwrapped
-if (TheLine->Last->is(tok::l_brace) && TheLine->First != TheLine->Last &&
+if (TheLine->Last->is(tok::l_brace) &&
 TheLine->First->isOneOf(tok::kw_if, tok::kw_while, tok::kw_for)) {
   return Style.AllowShortBlocksOnASingleLine != FormatStyle::SBS_Never
  ? tryMergeSimpleBlock(I, E, Limit)
  : 0;
 }
 // Try to merge a control statement block with left brace wrapped
-if (I[1]->First->is(tok::l_brace) &&
-(TheLine->First->isOneOf(tok::kw_if, tok::kw_else, tok::kw_while,
- tok::kw_for, tok::kw_switch, tok::kw_try,
- tok::kw_do, TT_ForEachMacro) ||
- (TheLine->First->is(tok::r_brace) && TheLine->First->Next &&
-  TheLine->First->Next->isOneOf(tok::kw_else, tok::kw_catch))) &&
-Style.BraceWrapping.AfterControlStatement ==
-FormatStyle::BWACS_MultiLine) {
-  // If possible, merge the next line's wrapped left brace with the current
-  // line. Otherwise, leave it on the next line, as this is a multi-line
-  // control statement.
-  return (Style.ColumnLimit == 0 ||
-  TheLine->Last->TotalLength <= Style.ColumnLimit)
- ? 1
- : 0;
-} else if (I[1]->First->is(tok::l_brace) &&
-   TheLine->First->isOneOf(tok::kw_if, tok::kw_else, tok::kw_while,
-   tok::kw_for)) {
-  return (Style.BraceWrapping.AfterControlStatement ==
-  FormatStyle::BWACS_Always)
- ? tryMergeSimpleBlock(I, E, Limit)
- : 0;
-} else if (I[1]->First->is(tok::l_brace) &&
-   TheLine->First->isOneOf(tok::kw_else, tok::kw_catch) &&
-   Style.BraceWrapping.AfterControlStatement ==
-   FormatStyle::BWACS_MultiLine) {
-  // This case if different from the upper BWACS_MultiLine processing
-  // in that a preceding r_brace is not on the same line as else/catch
-  // most likely because of BeforeElse/BeforeCatch set to true.
-  // If the line length doesn't fit ColumnLimit, leave l_brace on the
-  // next line to respect the BWACS_MultiLine.
-  return (Sty

[PATCH] D115061: [clang-format][NFC] Prefer pass by reference

2021-12-03 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks created this revision.
HazardyKnusperkeks added reviewers: owenpan, MyDeveloperDay, curdeius.
HazardyKnusperkeks added a project: clang-format.
HazardyKnusperkeks 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/D115061

Files:
  clang/lib/Format/UnwrappedLineFormatter.cpp


Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -1046,9 +1046,9 @@
 
   FormatDecision LastFormat = Node->State.NextToken->getDecision();
   if (LastFormat == FD_Unformatted || LastFormat == FD_Continue)
-addNextStateToQueue(Penalty, Node, /*NewLine=*/false, &Count, &Queue);
+addNextStateToQueue(Penalty, Node, /*NewLine=*/false, Count, Queue);
   if (LastFormat == FD_Unformatted || LastFormat == FD_Break)
-addNextStateToQueue(Penalty, Node, /*NewLine=*/true, &Count, &Queue);
+addNextStateToQueue(Penalty, Node, /*NewLine=*/true, Count, Queue);
 }
 
 if (Queue.empty()) {
@@ -1074,7 +1074,7 @@
   /// Assume the current state is \p PreviousNode and has been reached with a
   /// penalty of \p Penalty. Insert a line break if \p NewLine is \c true.
   void addNextStateToQueue(unsigned Penalty, StateNode *PreviousNode,
-   bool NewLine, unsigned *Count, QueueType *Queue) {
+   bool NewLine, unsigned &Count, QueueType &Queue) {
 if (NewLine && !Indenter->canBreak(PreviousNode->State))
   return;
 if (!NewLine && Indenter->mustBreak(PreviousNode->State))
@@ -1087,8 +1087,8 @@
 
 Penalty += Indenter->addTokenToState(Node->State, NewLine, true);
 
-Queue->push(QueueItem(OrderedPenalty(Penalty, *Count), Node));
-++(*Count);
+Queue.push(QueueItem(OrderedPenalty(Penalty, Count), Node));
+++Count;
   }
 
   /// Applies the best formatting by reconstructing the path in the


Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -1046,9 +1046,9 @@
 
   FormatDecision LastFormat = Node->State.NextToken->getDecision();
   if (LastFormat == FD_Unformatted || LastFormat == FD_Continue)
-addNextStateToQueue(Penalty, Node, /*NewLine=*/false, &Count, &Queue);
+addNextStateToQueue(Penalty, Node, /*NewLine=*/false, Count, Queue);
   if (LastFormat == FD_Unformatted || LastFormat == FD_Break)
-addNextStateToQueue(Penalty, Node, /*NewLine=*/true, &Count, &Queue);
+addNextStateToQueue(Penalty, Node, /*NewLine=*/true, Count, Queue);
 }
 
 if (Queue.empty()) {
@@ -1074,7 +1074,7 @@
   /// Assume the current state is \p PreviousNode and has been reached with a
   /// penalty of \p Penalty. Insert a line break if \p NewLine is \c true.
   void addNextStateToQueue(unsigned Penalty, StateNode *PreviousNode,
-   bool NewLine, unsigned *Count, QueueType *Queue) {
+   bool NewLine, unsigned &Count, QueueType &Queue) {
 if (NewLine && !Indenter->canBreak(PreviousNode->State))
   return;
 if (!NewLine && Indenter->mustBreak(PreviousNode->State))
@@ -1087,8 +1087,8 @@
 
 Penalty += Indenter->addTokenToState(Node->State, NewLine, true);
 
-Queue->push(QueueItem(OrderedPenalty(Penalty, *Count), Node));
-++(*Count);
+Queue.push(QueueItem(OrderedPenalty(Penalty, Count), Node));
+++Count;
   }
 
   /// Applies the best formatting by reconstructing the path in the
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 0a14674 - CodeGen: Strip exception specifications from function types in CFI type names.

2021-12-03 Thread Nico Weber via cfe-commits

Author: Peter Collingbourne
Date: 2021-12-03T14:50:52-05:00
New Revision: 0a14674f276b598d23353290635fc62f93e9ab30

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

LOG: CodeGen: Strip exception specifications from function types in CFI type 
names.

With C++17 the exception specification has been made part of the
function type, and therefore part of mangled type names.

However, it's valid to convert function pointers with an exception
specification to function pointers with the same argument and return
types but without an exception specification, which means that e.g. a
function of type "void () noexcept" can be called through a pointer
of type "void ()". We must therefore consider the two types to be
compatible for CFI purposes.

We can do this by stripping the exception specification before mangling
the type name, which is what this patch does.

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

Added: 
clang/test/CodeGenCXX/cfi-icall-noexcept.cpp

Modified: 
clang/lib/CodeGen/CodeGenModule.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 9ba1a5c25e81a..39044617d6774 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -6398,6 +6398,11 @@ void CodeGenModule::EmitOMPThreadPrivateDecl(const 
OMPThreadPrivateDecl *D) {
 llvm::Metadata *
 CodeGenModule::CreateMetadataIdentifierImpl(QualType T, MetadataTypeMap &Map,
 StringRef Suffix) {
+  if (auto *FnType = T->getAs())
+T = getContext().getFunctionType(
+FnType->getReturnType(), FnType->getParamTypes(),
+FnType->getExtProtoInfo().withExceptionSpec(EST_None));
+
   llvm::Metadata *&InternalId = Map[T.getCanonicalType()];
   if (InternalId)
 return InternalId;

diff  --git a/clang/test/CodeGenCXX/cfi-icall-noexcept.cpp 
b/clang/test/CodeGenCXX/cfi-icall-noexcept.cpp
new file mode 100644
index 0..eabc4862b4c52
--- /dev/null
+++ b/clang/test/CodeGenCXX/cfi-icall-noexcept.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -fsanitize=cfi-icall 
-emit-llvm -std=c++17 -o - %s | FileCheck %s
+
+// Tests that exception specifiers are stripped when forming the
+// mangled CFI type name.
+
+void f() noexcept {}
+
+// CHECK: define{{.*}} void @_Z1fv({{.*}} !type [[TS1:![0-9]+]] !type 
[[TS2:![0-9]+]]
+
+// CHECK: [[TS1]] = !{i64 0, !"_ZTSFvvE"}
+// CHECK: [[TS2]] = !{i64 0, !"_ZTSFvvE.generalized"}



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


[PATCH] D115063: [clang-format][NFC] Rename variable so no shadowing happens

2021-12-03 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks created this revision.
HazardyKnusperkeks added reviewers: MyDeveloperDay, owenpan, curdeius.
HazardyKnusperkeks added a project: clang-format.
HazardyKnusperkeks requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

In the loop there is also a Node.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D115063

Files:
  clang/lib/Format/UnwrappedLineFormatter.cpp


Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -1017,9 +1017,9 @@
 QueueType Queue;
 
 // Insert start element into queue.
-StateNode *Node =
+StateNode *RootNode =
 new (Allocator.Allocate()) StateNode(InitialState, false, nullptr);
-Queue.push(QueueItem(OrderedPenalty(0, Count), Node));
+Queue.push(QueueItem(OrderedPenalty(0, Count), RootNode));
 ++Count;
 
 unsigned Penalty = 0;


Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -1017,9 +1017,9 @@
 QueueType Queue;
 
 // Insert start element into queue.
-StateNode *Node =
+StateNode *RootNode =
 new (Allocator.Allocate()) StateNode(InitialState, false, nullptr);
-Queue.push(QueueItem(OrderedPenalty(0, Count), Node));
+Queue.push(QueueItem(OrderedPenalty(0, Count), RootNode));
 ++Count;
 
 unsigned Penalty = 0;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D115015: CodeGen: Strip exception specifications from function types in CFI type names.

2021-12-03 Thread Nico Weber via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0a14674f276b: CodeGen: Strip exception specifications from 
function types in CFI type names. (authored by pcc, committed by thakis).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115015

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGenCXX/cfi-icall-noexcept.cpp


Index: clang/test/CodeGenCXX/cfi-icall-noexcept.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/cfi-icall-noexcept.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -fsanitize=cfi-icall 
-emit-llvm -std=c++17 -o - %s | FileCheck %s
+
+// Tests that exception specifiers are stripped when forming the
+// mangled CFI type name.
+
+void f() noexcept {}
+
+// CHECK: define{{.*}} void @_Z1fv({{.*}} !type [[TS1:![0-9]+]] !type 
[[TS2:![0-9]+]]
+
+// CHECK: [[TS1]] = !{i64 0, !"_ZTSFvvE"}
+// CHECK: [[TS2]] = !{i64 0, !"_ZTSFvvE.generalized"}
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -6398,6 +6398,11 @@
 llvm::Metadata *
 CodeGenModule::CreateMetadataIdentifierImpl(QualType T, MetadataTypeMap &Map,
 StringRef Suffix) {
+  if (auto *FnType = T->getAs())
+T = getContext().getFunctionType(
+FnType->getReturnType(), FnType->getParamTypes(),
+FnType->getExtProtoInfo().withExceptionSpec(EST_None));
+
   llvm::Metadata *&InternalId = Map[T.getCanonicalType()];
   if (InternalId)
 return InternalId;


Index: clang/test/CodeGenCXX/cfi-icall-noexcept.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/cfi-icall-noexcept.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -fsanitize=cfi-icall -emit-llvm -std=c++17 -o - %s | FileCheck %s
+
+// Tests that exception specifiers are stripped when forming the
+// mangled CFI type name.
+
+void f() noexcept {}
+
+// CHECK: define{{.*}} void @_Z1fv({{.*}} !type [[TS1:![0-9]+]] !type [[TS2:![0-9]+]]
+
+// CHECK: [[TS1]] = !{i64 0, !"_ZTSFvvE"}
+// CHECK: [[TS2]] = !{i64 0, !"_ZTSFvvE.generalized"}
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -6398,6 +6398,11 @@
 llvm::Metadata *
 CodeGenModule::CreateMetadataIdentifierImpl(QualType T, MetadataTypeMap &Map,
 StringRef Suffix) {
+  if (auto *FnType = T->getAs())
+T = getContext().getFunctionType(
+FnType->getReturnType(), FnType->getParamTypes(),
+FnType->getExtProtoInfo().withExceptionSpec(EST_None));
+
   llvm::Metadata *&InternalId = Map[T.getCanonicalType()];
   if (InternalId)
 return InternalId;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D115015: CodeGen: Strip exception specifications from function types in CFI type names.

2021-12-03 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

I patched this in and verified that it fixes the make_top_domain_list_variables 
issue in https://bugs.chromium.org/p/chromium/issues/detail?id=1273966 and went 
ahead and landed this. Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115015

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


[PATCH] D115064: [clang-format][NFC] Replace deque with vector

2021-12-03 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks created this revision.
HazardyKnusperkeks added reviewers: MyDeveloperDay, curdeius, owenpan.
HazardyKnusperkeks added a project: clang-format.
HazardyKnusperkeks requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

I think the deque was chosen because of a better push_front, but in combination 
with llvm::reverse the push_back'ed vector should be the better choice.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D115064

Files:
  clang/lib/Format/UnwrappedLineFormatter.cpp


Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -1094,22 +1094,22 @@
   /// Applies the best formatting by reconstructing the path in the
   /// solution space that leads to \c Best.
   void reconstructPath(LineState &State, StateNode *Best) {
-std::deque Path;
+std::vector Path;
 // We do not need a break before the initial token.
 while (Best->Previous) {
-  Path.push_front(Best);
+  Path.push_back(Best);
   Best = Best->Previous;
 }
-for (auto I = Path.begin(), E = Path.end(); I != E; ++I) {
+for (const auto& Node : llvm::reverse(Path)) {
   unsigned Penalty = 0;
-  formatChildren(State, (*I)->NewLine, /*DryRun=*/false, Penalty);
-  Penalty += Indenter->addTokenToState(State, (*I)->NewLine, false);
+  formatChildren(State, Node->NewLine, /*DryRun=*/false, Penalty);
+  Penalty += Indenter->addTokenToState(State, Node->NewLine, false);
 
   LLVM_DEBUG({
-printLineState((*I)->Previous->State);
-if ((*I)->NewLine) {
+printLineState(Node->Previous->State);
+if (Node->NewLine) {
   llvm::dbgs() << "Penalty for placing "
-   << (*I)->Previous->State.NextToken->Tok.getName()
+   << Node->Previous->State.NextToken->Tok.getName()
<< " on a new line: " << Penalty << "\n";
 }
   });


Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -1094,22 +1094,22 @@
   /// Applies the best formatting by reconstructing the path in the
   /// solution space that leads to \c Best.
   void reconstructPath(LineState &State, StateNode *Best) {
-std::deque Path;
+std::vector Path;
 // We do not need a break before the initial token.
 while (Best->Previous) {
-  Path.push_front(Best);
+  Path.push_back(Best);
   Best = Best->Previous;
 }
-for (auto I = Path.begin(), E = Path.end(); I != E; ++I) {
+for (const auto& Node : llvm::reverse(Path)) {
   unsigned Penalty = 0;
-  formatChildren(State, (*I)->NewLine, /*DryRun=*/false, Penalty);
-  Penalty += Indenter->addTokenToState(State, (*I)->NewLine, false);
+  formatChildren(State, Node->NewLine, /*DryRun=*/false, Penalty);
+  Penalty += Indenter->addTokenToState(State, Node->NewLine, false);
 
   LLVM_DEBUG({
-printLineState((*I)->Previous->State);
-if ((*I)->NewLine) {
+printLineState(Node->Previous->State);
+if (Node->NewLine) {
   llvm::dbgs() << "Penalty for placing "
-   << (*I)->Previous->State.NextToken->Tok.getName()
+   << Node->Previous->State.NextToken->Tok.getName()
<< " on a new line: " << Penalty << "\n";
 }
   });
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D115065: [clang-format][NFC] Merge two calls of isOneOf

2021-12-03 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks created this revision.
HazardyKnusperkeks added reviewers: owenpan, MyDeveloperDay, curdeius.
HazardyKnusperkeks added a project: clang-format.
HazardyKnusperkeks 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/D115065

Files:
  clang/lib/Format/TokenAnnotator.cpp


Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -2034,9 +2034,8 @@
tok::comma, tok::semi, tok::kw_return, tok::colon,
tok::kw_co_return, tok::kw_co_await,
tok::kw_co_yield, tok::equal, tok::kw_delete,
-   tok::kw_sizeof, tok::kw_throw) ||
-PrevToken->isOneOf(TT_BinaryOperator, TT_ConditionalExpr,
-   TT_UnaryOperator, TT_CastRParen))
+   tok::kw_sizeof, tok::kw_throw, TT_BinaryOperator,
+   TT_ConditionalExpr, TT_UnaryOperator, 
TT_CastRParen))
   return TT_UnaryOperator;
 
 if (NextToken->is(tok::l_square) && NextToken->isNot(TT_LambdaLSquare))


Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -2034,9 +2034,8 @@
tok::comma, tok::semi, tok::kw_return, tok::colon,
tok::kw_co_return, tok::kw_co_await,
tok::kw_co_yield, tok::equal, tok::kw_delete,
-   tok::kw_sizeof, tok::kw_throw) ||
-PrevToken->isOneOf(TT_BinaryOperator, TT_ConditionalExpr,
-   TT_UnaryOperator, TT_CastRParen))
+   tok::kw_sizeof, tok::kw_throw, TT_BinaryOperator,
+   TT_ConditionalExpr, TT_UnaryOperator, TT_CastRParen))
   return TT_UnaryOperator;
 
 if (NextToken->is(tok::l_square) && NextToken->isNot(TT_LambdaLSquare))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D115066: [clang-format][NFC] Reorder conditions

2021-12-03 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks created this revision.
HazardyKnusperkeks added reviewers: owenpan, MyDeveloperDay, curdeius.
HazardyKnusperkeks added a project: clang-format.
HazardyKnusperkeks requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Prefer to check the local variables first before dereferencing the pointer.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D115066

Files:
  clang/lib/Format/TokenAnnotator.cpp


Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -2173,8 +2173,8 @@
 
   int CurrentPrecedence = getCurrentPrecedence();
 
-  if (Current && Current->is(TT_SelectorName) &&
-  Precedence == CurrentPrecedence) {
+  if (Precedence == CurrentPrecedence && Current &&
+  Current->is(TT_SelectorName)) {
 if (LatestOperator)
   addFakeParenthesis(Start, prec::Level(Precedence));
 Start = Current;


Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -2173,8 +2173,8 @@
 
   int CurrentPrecedence = getCurrentPrecedence();
 
-  if (Current && Current->is(TT_SelectorName) &&
-  Precedence == CurrentPrecedence) {
+  if (Precedence == CurrentPrecedence && Current &&
+  Current->is(TT_SelectorName)) {
 if (LatestOperator)
   addFakeParenthesis(Start, prec::Level(Precedence));
 Start = Current;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D115067: [clang-format][NFC] Use range based for

2021-12-03 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks created this revision.
HazardyKnusperkeks added reviewers: MyDeveloperDay, curdeius, owenpan.
HazardyKnusperkeks added a project: clang-format.
HazardyKnusperkeks requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

That's much easier to read.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D115067

Files:
  clang/lib/Format/TokenAnnotator.cpp


Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -2373,11 +2373,9 @@
 }
 
 void TokenAnnotator::annotate(AnnotatedLine &Line) {
-  for (SmallVectorImpl::iterator I = Line.Children.begin(),
-  E = Line.Children.end();
-   I != E; ++I) {
-annotate(**I);
-  }
+  for (auto &Child : Line.Children)
+annotate(*Child);
+
   AnnotatingParser Parser(Style, Line, Keywords);
   Line.Type = Parser.parseLine();
 


Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -2373,11 +2373,9 @@
 }
 
 void TokenAnnotator::annotate(AnnotatedLine &Line) {
-  for (SmallVectorImpl::iterator I = Line.Children.begin(),
-  E = Line.Children.end();
-   I != E; ++I) {
-annotate(**I);
-  }
+  for (auto &Child : Line.Children)
+annotate(*Child);
+
   AnnotatingParser Parser(Style, Line, Keywords);
   Line.Type = Parser.parseLine();
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D115068: [clang-format][NFC] Move static variable in scope

2021-12-03 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks created this revision.
HazardyKnusperkeks added reviewers: MyDeveloperDay, curdeius, owenpan.
HazardyKnusperkeks added a project: clang-format.
HazardyKnusperkeks requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Let only the JS/TS users pay for the initialistation.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D115068

Files:
  clang/lib/Format/ContinuationIndenter.cpp


Index: clang/lib/Format/ContinuationIndenter.cpp
===
--- clang/lib/Format/ContinuationIndenter.cpp
+++ clang/lib/Format/ContinuationIndenter.cpp
@@ -493,14 +493,14 @@
   return true;
   }
 
-  // Break after the closing parenthesis of TypeScript decorators before
-  // functions, getters and setters.
-  static const llvm::StringSet<> BreakBeforeDecoratedTokens = {"get", "set",
-   "function"};
   if (Style.Language == FormatStyle::LK_JavaScript &&
-  BreakBeforeDecoratedTokens.contains(Current.TokenText) &&
   Previous.is(tok::r_paren) && Previous.is(TT_JavaAnnotation)) {
-return true;
+// Break after the closing parenthesis of TypeScript decorators before
+// functions, getters and setters.
+static const llvm::StringSet<> BreakBeforeDecoratedTokens = {"get", "set",
+ "function"};
+if (BreakBeforeDecoratedTokens.contains(Current.TokenText))
+  return true;
   }
 
   // If the return type spans multiple lines, wrap before the function name.


Index: clang/lib/Format/ContinuationIndenter.cpp
===
--- clang/lib/Format/ContinuationIndenter.cpp
+++ clang/lib/Format/ContinuationIndenter.cpp
@@ -493,14 +493,14 @@
   return true;
   }
 
-  // Break after the closing parenthesis of TypeScript decorators before
-  // functions, getters and setters.
-  static const llvm::StringSet<> BreakBeforeDecoratedTokens = {"get", "set",
-   "function"};
   if (Style.Language == FormatStyle::LK_JavaScript &&
-  BreakBeforeDecoratedTokens.contains(Current.TokenText) &&
   Previous.is(tok::r_paren) && Previous.is(TT_JavaAnnotation)) {
-return true;
+// Break after the closing parenthesis of TypeScript decorators before
+// functions, getters and setters.
+static const llvm::StringSet<> BreakBeforeDecoratedTokens = {"get", "set",
+ "function"};
+if (BreakBeforeDecoratedTokens.contains(Current.TokenText))
+  return true;
   }
 
   // If the return type spans multiple lines, wrap before the function name.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D115069: [clang-format][NFC] Merge another two calls to isOneOf

2021-12-03 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks created this revision.
HazardyKnusperkeks added reviewers: MyDeveloperDay, curdeius, owenpan.
HazardyKnusperkeks added a project: clang-format.
HazardyKnusperkeks 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/D115069

Files:
  clang/lib/Format/ContinuationIndenter.cpp


Index: clang/lib/Format/ContinuationIndenter.cpp
===
--- clang/lib/Format/ContinuationIndenter.cpp
+++ clang/lib/Format/ContinuationIndenter.cpp
@@ -1291,8 +1291,8 @@
 State.Stack[State.Stack.size() - 2].NestedBlockInlined = false;
   }
   if (Previous &&
-  (Previous->isOneOf(tok::l_paren, tok::comma, tok::colon) ||
-   Previous->isOneOf(TT_BinaryOperator, TT_ConditionalExpr)) &&
+  Previous->isOneOf(tok::l_paren, tok::comma, tok::colon, 
TT_BinaryOperator,
+TT_ConditionalExpr) &&
   !Previous->isOneOf(TT_DictLiteral, TT_ObjCMethodExpr)) {
 State.Stack.back().NestedBlockInlined =
 !Newline && hasNestedBlockInlined(Previous, Current, Style);


Index: clang/lib/Format/ContinuationIndenter.cpp
===
--- clang/lib/Format/ContinuationIndenter.cpp
+++ clang/lib/Format/ContinuationIndenter.cpp
@@ -1291,8 +1291,8 @@
 State.Stack[State.Stack.size() - 2].NestedBlockInlined = false;
   }
   if (Previous &&
-  (Previous->isOneOf(tok::l_paren, tok::comma, tok::colon) ||
-   Previous->isOneOf(TT_BinaryOperator, TT_ConditionalExpr)) &&
+  Previous->isOneOf(tok::l_paren, tok::comma, tok::colon, TT_BinaryOperator,
+TT_ConditionalExpr) &&
   !Previous->isOneOf(TT_DictLiteral, TT_ObjCMethodExpr)) {
 State.Stack.back().NestedBlockInlined =
 !Newline && hasNestedBlockInlined(Previous, Current, Style);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D115070: [clang-format][NFC] Early return when nothing to do

2021-12-03 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks created this revision.
HazardyKnusperkeks added reviewers: MyDeveloperDay, owenpan, curdeius.
HazardyKnusperkeks added a project: clang-format.
HazardyKnusperkeks requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Do not compute SkipFirstExtraIndent just to see that there are no fake l parens.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D115070

Files:
  clang/lib/Format/ContinuationIndenter.cpp


Index: clang/lib/Format/ContinuationIndenter.cpp
===
--- clang/lib/Format/ContinuationIndenter.cpp
+++ clang/lib/Format/ContinuationIndenter.cpp
@@ -1337,6 +1337,9 @@
 void ContinuationIndenter::moveStatePastFakeLParens(LineState &State,
 bool Newline) {
   const FormatToken &Current = *State.NextToken;
+  if (Current.FakeLParens.empty())
+return;
+
   const FormatToken *Previous = Current.getPreviousNonComment();
 
   // Don't add extra indentation for the first fake parenthesis after


Index: clang/lib/Format/ContinuationIndenter.cpp
===
--- clang/lib/Format/ContinuationIndenter.cpp
+++ clang/lib/Format/ContinuationIndenter.cpp
@@ -1337,6 +1337,9 @@
 void ContinuationIndenter::moveStatePastFakeLParens(LineState &State,
 bool Newline) {
   const FormatToken &Current = *State.NextToken;
+  if (Current.FakeLParens.empty())
+return;
+
   const FormatToken *Previous = Current.getPreviousNonComment();
 
   // Don't add extra indentation for the first fake parenthesis after
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D115071: [clang-format][NFC] Use range based for for fake l parens

2021-12-03 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks created this revision.
HazardyKnusperkeks added reviewers: MyDeveloperDay, curdeius, owenpan.
HazardyKnusperkeks added a project: clang-format.
HazardyKnusperkeks 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/D115071

Files:
  clang/lib/Format/ContinuationIndenter.cpp


Index: clang/lib/Format/ContinuationIndenter.cpp
===
--- clang/lib/Format/ContinuationIndenter.cpp
+++ clang/lib/Format/ContinuationIndenter.cpp
@@ -1351,10 +1351,7 @@
 (Previous->getPrecedence() == prec::Assignment &&
  Style.AlignOperands != FormatStyle::OAS_DontAlign) ||
 Previous->is(TT_ObjCMethodExpr)));
-  for (SmallVectorImpl::const_reverse_iterator
-   I = Current.FakeLParens.rbegin(),
-   E = Current.FakeLParens.rend();
-   I != E; ++I) {
+  for (const auto &PrecedenceLevel : llvm::reverse(Current.FakeLParens)) {
 ParenState NewParenState = State.Stack.back();
 NewParenState.Tok = nullptr;
 NewParenState.ContainsLineBreak = false;
@@ -1366,7 +1363,7 @@
 NewParenState.NoLineBreak || State.Stack.back().NoLineBreakInOperand;
 
 // Don't propagate AvoidBinPacking into subexpressions of arg/param lists.
-if (*I > prec::Comma)
+if (PrecedenceLevel > prec::Comma)
   NewParenState.AvoidBinPacking = false;
 
 // Indent from 'LastSpace' unless these are fake parentheses encapsulating
@@ -1374,11 +1371,11 @@
 // brackets is disabled.
 if (!Current.isTrailingComment() &&
 (Style.AlignOperands != FormatStyle::OAS_DontAlign ||
- *I < prec::Assignment) &&
+ PrecedenceLevel < prec::Assignment) &&
 (!Previous || Previous->isNot(tok::kw_return) ||
- (Style.Language != FormatStyle::LK_Java && *I > 0)) &&
+ (Style.Language != FormatStyle::LK_Java && PrecedenceLevel > 0)) &&
 (Style.AlignAfterOpenBracket != FormatStyle::BAS_DontAlign ||
- *I != prec::Comma || Current.NestingLevel == 0)) {
+ PrecedenceLevel != prec::Comma || Current.NestingLevel == 0)) {
   NewParenState.Indent =
   std::max(std::max(State.Column, NewParenState.Indent),
State.Stack.back().LastSpace);
@@ -1387,7 +1384,7 @@
 if (Previous &&
 (Previous->getPrecedence() == prec::Assignment ||
  Previous->is(tok::kw_return) ||
- (*I == prec::Conditional && Previous->is(tok::question) &&
+ (PrecedenceLevel == prec::Conditional && Previous->is(tok::question) 
&&
   Previous->is(TT_ConditionalExpr))) &&
 !Newline) {
   // If BreakBeforeBinaryOperators is set, un-indent a bit to account for
@@ -1405,9 +1402,9 @@
 //   ParameterToInnerFunction));
 //   OuterFunction(SomeObject.InnerFunctionCall( // break
 //   ParameterToInnerFunction));
-if (*I > prec::Unknown)
+if (PrecedenceLevel > prec::Unknown)
   NewParenState.LastSpace = std::max(NewParenState.LastSpace, 
State.Column);
-if (*I != prec::Conditional && !Current.is(TT_UnaryOperator) &&
+if (PrecedenceLevel != prec::Conditional && !Current.is(TT_UnaryOperator) 
&&
 Style.AlignAfterOpenBracket != FormatStyle::BAS_DontAlign)
   NewParenState.StartOfFunctionCall = State.Column;
 
@@ -1416,17 +1413,18 @@
 // an assignment (i.e. *I <= prec::Assignment) as those have different
 // indentation rules. Indent other expression, unless the indentation needs
 // to be skipped.
-if (*I == prec::Conditional && Previous && Previous->is(tok::colon) &&
-Previous->is(TT_ConditionalExpr) && I == Current.FakeLParens.rbegin() 
&&
+if (PrecedenceLevel == prec::Conditional && Previous &&
+Previous->is(tok::colon) && Previous->is(TT_ConditionalExpr) &&
+&PrecedenceLevel == &Current.FakeLParens.back() &&
 !State.Stack.back().IsWrappedConditional) {
   NewParenState.IsChainedConditional = true;
   NewParenState.UnindentOperator = State.Stack.back().UnindentOperator;
-} else if (*I == prec::Conditional ||
-   (!SkipFirstExtraIndent && *I > prec::Assignment &&
+} else if (PrecedenceLevel == prec::Conditional ||
+   (!SkipFirstExtraIndent && PrecedenceLevel > prec::Assignment &&
 !Current.isTrailingComment())) {
   NewParenState.Indent += Style.ContinuationIndentWidth;
 }
-if ((Previous && !Previous->opensScope()) || *I != prec::Comma)
+if ((Previous && !Previous->opensScope()) || PrecedenceLevel != 
prec::Comma)
   NewParenState.BreakBeforeParameter = false;
 State.Stack.push_back(NewParenState);
 SkipFirstExtraIndent = false;


Index: clang/lib/Format/ContinuationIndenter.cpp
===
--- clang/lib/Format/ContinuationIndenter.cpp
+++ clang/

[PATCH] D115072: [clang-format][NFC] Use member directly

2021-12-03 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks created this revision.
HazardyKnusperkeks added reviewers: MyDeveloperDay, curdeius, owenpan.
HazardyKnusperkeks added a project: clang-format.
HazardyKnusperkeks requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Instead of passing it as argument to the member function.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D115072

Files:
  clang/lib/Format/UnwrappedLineFormatter.cpp


Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -62,7 +62,7 @@
   Indent = Line.Level * IndentWidth + AdditionalIndent;
 } else {
   IndentForLevel.resize(Line.Level + 1);
-  Indent = getIndent(IndentForLevel, Line.Level);
+  Indent = getIndent(Line.Level);
 }
 if (static_cast(Indent) + Offset >= 0)
   Indent += Offset;
@@ -118,12 +118,12 @@
   /// \p IndentForLevel must contain the indent for the level \c l
   /// at \p IndentForLevel[l], or a value < 0 if the indent for
   /// that level is unknown.
-  unsigned getIndent(ArrayRef IndentForLevel, unsigned Level) {
+  unsigned getIndent(unsigned Level) const {
 if (IndentForLevel[Level] != -1)
   return IndentForLevel[Level];
 if (Level == 0)
   return 0;
-return getIndent(IndentForLevel, Level - 1) + Style.IndentWidth;
+return getIndent(Level - 1) + Style.IndentWidth;
   }
 
   const FormatStyle &Style;


Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -62,7 +62,7 @@
   Indent = Line.Level * IndentWidth + AdditionalIndent;
 } else {
   IndentForLevel.resize(Line.Level + 1);
-  Indent = getIndent(IndentForLevel, Line.Level);
+  Indent = getIndent(Line.Level);
 }
 if (static_cast(Indent) + Offset >= 0)
   Indent += Offset;
@@ -118,12 +118,12 @@
   /// \p IndentForLevel must contain the indent for the level \c l
   /// at \p IndentForLevel[l], or a value < 0 if the indent for
   /// that level is unknown.
-  unsigned getIndent(ArrayRef IndentForLevel, unsigned Level) {
+  unsigned getIndent(unsigned Level) const {
 if (IndentForLevel[Level] != -1)
   return IndentForLevel[Level];
 if (Level == 0)
   return 0;
-return getIndent(IndentForLevel, Level - 1) + Style.IndentWidth;
+return getIndent(Level - 1) + Style.IndentWidth;
   }
 
   const FormatStyle &Style;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D113369: [clang-format] Extend SpaceBeforeParens for requires

2021-12-03 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks planned changes to this revision.
HazardyKnusperkeks marked an inline comment as done.
HazardyKnusperkeks added a comment.

Delayed until D113319  is resolved.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113369

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


[PATCH] D113319: [clang-format] Improve require and concept handling

2021-12-03 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks updated this revision to Diff 391708.
HazardyKnusperkeks retitled this revision from "[clang-format] Improve require 
handling" to "[clang-format] Improve require and concept handling".
HazardyKnusperkeks edited the summary of this revision.
HazardyKnusperkeks added reviewers: gonzalobg, CaseyCarter.
HazardyKnusperkeks added a comment.
This revision is now accepted and ready to land.

Update on my work in progress. The new test cases are all passed. The old ones 
are only kept to pick some lines from them.

I would like to hear some feedback while I finish the rest, mostly writing 
tests.


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

https://reviews.llvm.org/D113319

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/ContinuationIndenter.cpp
  clang/lib/Format/Format.cpp
  clang/lib/Format/FormatToken.h
  clang/lib/Format/TokenAnnotator.cpp
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/lib/Format/UnwrappedLineParser.h
  clang/unittests/Format/FormatTest.cpp
  clang/unittests/Format/TokenAnnotatorTest.cpp

Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -67,6 +67,51 @@
   EXPECT_TOKEN(Tokens[11], tok::star, TT_PointerOrReference);
 }
 
+TEST_F(TokenAnnotatorTest, UnderstandsRequiresClauses) {
+  auto Tokens = annotate("template \n"
+ "concept C = (Foo && Bar) && (Bar && Baz);");
+
+  EXPECT_EQ(Tokens.size(), 21u) << Tokens;
+  EXPECT_TOKEN(Tokens[10], tok::ampamp, TT_BinaryOperator);
+  EXPECT_TOKEN(Tokens[13], tok::ampamp, TT_BinaryOperator);
+  EXPECT_TOKEN(Tokens[16], tok::ampamp, TT_BinaryOperator);
+
+  Tokens = annotate("template \n"
+"concept C = requires(T t) {\n"
+"  { t.foo() };\n"
+"} && Bar && Baz;");
+  EXPECT_EQ(Tokens.size(), 35u) << Tokens;
+  EXPECT_TOKEN(Tokens[23], tok::ampamp, TT_BinaryOperator);
+  EXPECT_TOKEN(Tokens[28], tok::ampamp, TT_BinaryOperator);
+
+  Tokens = annotate("template\n"
+"requires C1 && (C21 || C22 && C2e) && C3\n"
+"struct Foo;");
+  EXPECT_EQ(Tokens.size(), 36u) << Tokens;
+  EXPECT_TOKEN(Tokens[6], tok::identifier, TT_Unknown);
+  EXPECT_EQ(Tokens[6]->FakeLParens.size(), 1u);
+  EXPECT_TOKEN(Tokens[10], tok::ampamp, TT_BinaryOperator);
+  EXPECT_TOKEN(Tokens[16], tok::pipepipe, TT_BinaryOperator);
+  EXPECT_TOKEN(Tokens[21], tok::ampamp, TT_BinaryOperator);
+  EXPECT_TOKEN(Tokens[27], tok::ampamp, TT_BinaryOperator);
+  EXPECT_TOKEN(Tokens[31], tok::greater, TT_TemplateCloser);
+  EXPECT_EQ(Tokens[31]->FakeRParens, 1u);
+
+  Tokens =
+  annotate("template\n"
+   "requires (C1 && (C21 || C22 && C2e) && C3)\n"
+   "struct Foo;");
+  EXPECT_EQ(Tokens.size(), 38u) << Tokens;
+  EXPECT_TOKEN(Tokens[7], tok::identifier, TT_Unknown);
+  EXPECT_EQ(Tokens[7]->FakeLParens.size(), 1u);
+  EXPECT_TOKEN(Tokens[11], tok::ampamp, TT_BinaryOperator);
+  EXPECT_TOKEN(Tokens[17], tok::pipepipe, TT_BinaryOperator);
+  EXPECT_TOKEN(Tokens[22], tok::ampamp, TT_BinaryOperator);
+  EXPECT_TOKEN(Tokens[28], tok::ampamp, TT_BinaryOperator);
+  EXPECT_TOKEN(Tokens[32], tok::greater, TT_TemplateCloser);
+  EXPECT_EQ(Tokens[32]->FakeRParens, 1u);
+}
+
 } // namespace
 } // namespace format
 } // namespace clang
Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -19143,6 +19143,30 @@
   // For backward compatibility:
   CHECK_PARSE("SpacesInAngles: false", SpacesInAngles, FormatStyle::SIAS_Never);
   CHECK_PARSE("SpacesInAngles: true", SpacesInAngles, FormatStyle::SIAS_Always);
+
+  CHECK_PARSE("RequiresClausePositionForClasses: ToPreceeding",
+  RequiresClausePositionForClasses, FormatStyle::RCPS_ToPreceeding);
+  CHECK_PARSE("RequiresClausePositionForClasses: ToFollowing",
+  RequiresClausePositionForClasses, FormatStyle::RCPS_ToFollowing);
+  CHECK_PARSE("RequiresClausePositionForClasses: SingleLine",
+  RequiresClausePositionForClasses, FormatStyle::RCPS_SingleLine);
+  CHECK_PARSE("RequiresClausePositionForClasses: TwoLines",
+  RequiresClausePositionForClasses, FormatStyle::RCPS_TwoLines);
+  CHECK_PARSE("RequiresClausePositionForClasses: OwnLine",
+  RequiresClausePositionForClasses, FormatStyle::RCPS_OwnLine);
+
+  CHECK_PARSE("RequiresClausePositionForFunctions: ToPreceeding",
+  RequiresClausePositionForFunctions,
+  FormatStyle::RCPS_ToPreceeding);
+  CHECK_PARSE("RequiresClausePositionForFunctions: ToFollowing",
+  RequiresClausePositionForFunctions,
+  FormatStyle::RCPS_ToFoll

[PATCH] D113319: [clang-format] Improve require and concept handling

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

Still WIP, not marking as changes planned, so that it pops up on your list and 
you can give me feedback. :)




Comment at: clang/lib/Format/Format.cpp:1213
+  // This is open for discussions! When will LLVM adapt C++20?
+  LLVMStyle.RequiresClausePositionForClasses = FormatStyle::RCPS_OwnLine;
+  LLVMStyle.RequiresClausePositionForFunctions = FormatStyle::RCPS_OwnLine;

What are your opinions on that?



Comment at: clang/lib/Format/UnwrappedLineParser.cpp:435
 
-void UnwrappedLineParser::parseLevel(bool HasOpeningBrace) {
+/// \brief Parses a level, that is ???.
+/// \param HasOpeningBrace If that level is started by an opening brace.

Does anyone know for sure what the level is? I have an idea, but I'm not 100% 
sure yet.



Comment at: clang/lib/Format/UnwrappedLineParser.cpp:2643
+  RequiresToken->setType(TT_RequiresClauseForFunctions);
+// Else: We are a requires clause within a requires expression.
+// The Semi is eaten by the caller, he also adds the unwrapped line.

Here I have an requires for a requires clause which did not get a type. Same as 
requires for requires expressions right now.

Should I tag all of them, even if I do not use the type right now?



Comment at: clang/lib/Format/UnwrappedLineParser.cpp:2727
 
-void UnwrappedLineParser::parseRequires() {
+/*void UnwrappedLineParser::parseRequires() {
   assert(FormatTok->Tok.is(tok::kw_requires) && "'requires' expected");

This will be removed.



Comment at: clang/unittests/Format/FormatTest.cpp:22715-22717
+   "  typename T::Bar;\n"
+   "  { t.bar() } -> std::same_as;\n"
+   "}\n"

Should these lines be indented because requires is indented, or not?


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

https://reviews.llvm.org/D113319

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


[PATCH] D115050: [clang-format] PR48916 PointerAlignment not working when using C++20 init-statement in for loop

2021-12-03 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added inline comments.



Comment at: clang/lib/Format/TokenAnnotator.cpp:3052
+// & 1
+if (Right.Tok.isLiteral())
+  return true;

MyDeveloperDay wrote:
> HazardyKnusperkeks wrote:
> > Is this valid code? Or did we just wrongly assign PointerOrReference? I'd 
> > say after that there can not be a literal in valid code, thus we do not 
> > need to handle it.
> Ok so as you see I broken out the compound statement, to be honest I find 
> these compound if's unreadable and I can't for the life of me work out what 
> case they are trying to handle. (I want to do this more)..
> 
> Please no one say doing it separately is slower! without measuring it..we are 
> talking ns difference if anything at all.
> 
> I agree I truly believe we are mis assigning 
> PointerOrReference/BinaryOperator this as I mentioned  in
> https://lists.llvm.org/pipermail/cfe-dev/2021-December/069486.html is a major 
> issue and I think from time to time these rules try to correct that 
> situation, in this case & is the logical operation on a reference.
I'm with you to split up these monsters!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115050

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


[PATCH] D115072: [clang-format][NFC] Use member directly

2021-12-03 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius accepted this revision.
curdeius added a comment.
This revision is now accepted and ready to land.

LGTM if CI is happy.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115072

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


[PATCH] D115071: [clang-format][NFC] Use range based for for fake l parens

2021-12-03 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius accepted this revision.
curdeius 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/D115071/new/

https://reviews.llvm.org/D115071

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


[PATCH] D115070: [clang-format][NFC] Early return when nothing to do

2021-12-03 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius accepted this revision.
curdeius 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/D115070/new/

https://reviews.llvm.org/D115070

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


[PATCH] D115069: [clang-format][NFC] Merge another two calls to isOneOf

2021-12-03 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius added inline comments.



Comment at: clang/lib/Format/ContinuationIndenter.cpp:1294-1296
+  Previous->isOneOf(tok::l_paren, tok::comma, tok::colon, 
TT_BinaryOperator,
+TT_ConditionalExpr) &&
   !Previous->isOneOf(TT_DictLiteral, TT_ObjCMethodExpr)) {

Unrelated to your change, it only shed light on this:
This condition looks strange to me. How can `Previous` be at the same time two 
different `TokenType`s (?), for instance, both `TT_BinaryOperator` and 
`TT_DictLiteral`?

Shouldn't it be this?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115069

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


  1   2   >