[PATCH] D111119: [Clang][OpenMP] Infix OMPLoopTransformationDirective abstract class. NFC.

2021-10-05 Thread Michael Kruse via Phabricator via cfe-commits
Meinersbur updated this revision to Diff 377099.
Meinersbur added a comment.

Re-sync


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D19

Files:
  clang/include/clang/AST/StmtOpenMP.h
  clang/include/clang/Basic/StmtNodes.td
  clang/lib/AST/StmtOpenMP.cpp
  clang/lib/AST/StmtProfile.cpp
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/tools/libclang/CIndex.cpp

Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -2046,6 +2046,8 @@
   void VisitOMPLoopDirective(const OMPLoopDirective *D);
   void VisitOMPParallelDirective(const OMPParallelDirective *D);
   void VisitOMPSimdDirective(const OMPSimdDirective *D);
+  void
+  VisitOMPLoopTransformationDirective(const OMPLoopTransformationDirective *D);
   void VisitOMPTileDirective(const OMPTileDirective *D);
   void VisitOMPUnrollDirective(const OMPUnrollDirective *D);
   void VisitOMPForDirective(const OMPForDirective *D);
@@ -2901,12 +2903,17 @@
   VisitOMPLoopDirective(D);
 }
 
-void EnqueueVisitor::VisitOMPTileDirective(const OMPTileDirective *D) {
+void EnqueueVisitor::VisitOMPLoopTransformationDirective(
+const OMPLoopTransformationDirective *D) {
   VisitOMPLoopBasedDirective(D);
 }
 
+void EnqueueVisitor::VisitOMPTileDirective(const OMPTileDirective *D) {
+  VisitOMPLoopTransformationDirective(D);
+}
+
 void EnqueueVisitor::VisitOMPUnrollDirective(const OMPUnrollDirective *D) {
-  VisitOMPLoopBasedDirective(D);
+  VisitOMPLoopTransformationDirective(D);
 }
 
 void EnqueueVisitor::VisitOMPForDirective(const OMPForDirective *D) {
Index: clang/lib/Serialization/ASTWriterStmt.cpp
===
--- clang/lib/Serialization/ASTWriterStmt.cpp
+++ clang/lib/Serialization/ASTWriterStmt.cpp
@@ -2224,13 +2224,18 @@
   Code = serialization::STMT_OMP_SIMD_DIRECTIVE;
 }
 
-void ASTStmtWriter::VisitOMPTileDirective(OMPTileDirective *D) {
+void ASTStmtWriter::VisitOMPLoopTransformationDirective(
+OMPLoopTransformationDirective *D) {
   VisitOMPLoopBasedDirective(D);
+}
+
+void ASTStmtWriter::VisitOMPTileDirective(OMPTileDirective *D) {
+  VisitOMPLoopTransformationDirective(D);
   Code = serialization::STMT_OMP_TILE_DIRECTIVE;
 }
 
 void ASTStmtWriter::VisitOMPUnrollDirective(OMPUnrollDirective *D) {
-  VisitOMPLoopBasedDirective(D);
+  VisitOMPLoopTransformationDirective(D);
   Code = serialization::STMT_OMP_UNROLL_DIRECTIVE;
 }
 
Index: clang/lib/Serialization/ASTReaderStmt.cpp
===
--- clang/lib/Serialization/ASTReaderStmt.cpp
+++ clang/lib/Serialization/ASTReaderStmt.cpp
@@ -2324,12 +2324,17 @@
   VisitOMPLoopDirective(D);
 }
 
-void ASTStmtReader::VisitOMPTileDirective(OMPTileDirective *D) {
+void ASTStmtReader::VisitOMPLoopTransformationDirective(
+OMPLoopTransformationDirective *D) {
   VisitOMPLoopBasedDirective(D);
 }
 
+void ASTStmtReader::VisitOMPTileDirective(OMPTileDirective *D) {
+  VisitOMPLoopTransformationDirective(D);
+}
+
 void ASTStmtReader::VisitOMPUnrollDirective(OMPUnrollDirective *D) {
-  VisitOMPLoopBasedDirective(D);
+  VisitOMPLoopTransformationDirective(D);
 }
 
 void ASTStmtReader::VisitOMPForDirective(OMPForDirective *D) {
Index: clang/lib/Sema/SemaOpenMP.cpp
===
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -3823,13 +3823,8 @@
 VisitSubCaptures(S);
   }
 
-  void VisitOMPTileDirective(OMPTileDirective *S) {
-// #pragma omp tile does not introduce data sharing.
-VisitStmt(S);
-  }
-
-  void VisitOMPUnrollDirective(OMPUnrollDirective *S) {
-// #pragma omp unroll does not introduce data sharing.
+  void VisitOMPLoopTransformationDirective(OMPLoopTransformationDirective *S) {
+// Loop transformation directives do not introduce data sharing
 VisitStmt(S);
   }
 
@@ -9050,15 +9045,8 @@
 }
 return false;
   },
-  [&SemaRef, &Captures](OMPLoopBasedDirective *Transform) {
-Stmt *DependentPreInits;
-if (auto *Dir = dyn_cast(Transform)) {
-  DependentPreInits = Dir->getPreInits();
-} else if (auto *Dir = dyn_cast(Transform)) {
-  DependentPreInits = Dir->getPreInits();
-} else {
-  llvm_unreachable("Unexpected loop transformation");
-}
+  [&SemaRef, &Captures](OMPLoopTransformationDirective *Transform) {
+Stmt *DependentPreInits = Transform->getPreInits();
 if (!DependentPreInits)
   return;
 for (Decl *C : cast(DependentPreInits)->getDeclGroup()) {
Index: clang/lib/CodeGen/CGStmtOpenMP.cpp

[PATCH] D110614: [clang-tidy] Fix false positives in cppcoreguidelines-virtual-class-destructor

2021-10-05 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp updated this revision to Diff 377100.
carlosgalvezp added a comment.

Added test where an alias to the class template is created. @whisperity let me 
know if that's what you meant!


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

https://reviews.llvm.org/D110614

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/VirtualClassDestructorCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-virtual-class-destructor.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-virtual-class-destructor.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-virtual-class-destructor.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-virtual-class-destructor.cpp
@@ -202,3 +202,73 @@
   void m();
 };
 // inherits virtual method
+
+namespace Bugzilla_51912 {
+// Fixes https://bugs.llvm.org/show_bug.cgi?id=51912
+
+// Forward declarations
+// CHECK-MESSAGES-NOT: :[[@LINE+1]]:8: warning: destructor of 'ForwardDeclaredStruct' is public and non-virtual [cppcoreguidelines-virtual-class-destructor]
+struct ForwardDeclaredStruct;
+
+struct ForwardDeclaredStruct : PublicVirtualBaseStruct {
+};
+
+// Normal Template
+// CHECK-MESSAGES-NOT: :[[@LINE+2]]:8: warning: destructor of 'TemplatedDerived' is public and non-virtual [cppcoreguidelines-virtual-class-destructor]
+template 
+struct TemplatedDerived : PublicVirtualBaseStruct {
+};
+
+TemplatedDerived InstantiationWithInt;
+
+// Derived from template, base has virtual dtor
+// CHECK-MESSAGES-NOT: :[[@LINE+2]]:8: warning: destructor of 'DerivedFromTemplateVirtualBaseStruct' is public and non-virtual [cppcoreguidelines-virtual-class-destructor]
+template 
+struct DerivedFromTemplateVirtualBaseStruct : T {
+  virtual void foo();
+};
+
+DerivedFromTemplateVirtualBaseStruct InstantiationWithPublicVirtualBaseStruct;
+
+// Derived from template, base has *not* virtual dtor
+// CHECK-MESSAGES: :[[@LINE+8]]:8: warning: destructor of 'DerivedFromTemplateNonVirtualBaseStruct' is public and non-virtual [cppcoreguidelines-virtual-class-destructor]
+// CHECK-MESSAGES: :[[@LINE+7]]:8: note: make it public and virtual
+// CHECK-MESSAGES: :[[@LINE+6]]:8: warning: destructor of 'DerivedFromTemplateNonVirtualBaseStruct' is public and non-virtual [cppcoreguidelines-virtual-class-destructor]
+// CHECK-FIXES: struct DerivedFromTemplateNonVirtualBaseStruct : T {
+// CHECK-FIXES-NEXT: virtual ~DerivedFromTemplateNonVirtualBaseStruct() = default;
+// CHECK-FIXES-NEXT: virtual void foo();
+// CHECK-FIXES-NEXT: };
+template 
+struct DerivedFromTemplateNonVirtualBaseStruct : T {
+  virtual void foo();
+};
+
+DerivedFromTemplateNonVirtualBaseStruct InstantiationWithPublicNonVirtualBaseStruct;
+
+// Derived from template, base has virtual dtor, to be used in a typedef
+// CHECK-MESSAGES-NOT: :[[@LINE+2]]:8: warning: destructor of 'DerivedFromTemplateVirtualBaseStruct2' is public and non-virtual [cppcoreguidelines-virtual-class-destructor]
+template 
+struct DerivedFromTemplateVirtualBaseStruct2 : T {
+  virtual void foo();
+};
+
+using DerivedFromTemplateVirtualBaseStruct2Typedef = DerivedFromTemplateVirtualBaseStruct2;
+DerivedFromTemplateVirtualBaseStruct2Typedef InstantiationWithPublicVirtualBaseStruct2;
+
+// Derived from template, base has *not* virtual dtor, to be used in a typedef
+// CHECK-MESSAGES: :[[@LINE+8]]:8: warning: destructor of 'DerivedFromTemplateNonVirtualBaseStruct2' is public and non-virtual [cppcoreguidelines-virtual-class-destructor]
+// CHECK-MESSAGES: :[[@LINE+7]]:8: note: make it public and virtual
+// CHECK-MESSAGES: :[[@LINE+6]]:8: warning: destructor of 'DerivedFromTemplateNonVirtualBaseStruct2' is public and non-virtual [cppcoreguidelines-virtual-class-destructor]
+// CHECK-FIXES: struct DerivedFromTemplateNonVirtualBaseStruct2 : T {
+// CHECK-FIXES-NEXT: virtual ~DerivedFromTemplateNonVirtualBaseStruct2() = default;
+// CHECK-FIXES-NEXT: virtual void foo();
+// CHECK-FIXES-NEXT: };
+template 
+struct DerivedFromTemplateNonVirtualBaseStruct2 : T {
+  virtual void foo();
+};
+
+using DerivedFromTemplateNonVirtualBaseStruct2Typedef = DerivedFromTemplateNonVirtualBaseStruct2;
+DerivedFromTemplateNonVirtualBaseStruct2Typedef InstantiationWithPublicNonVirtualBaseStruct2;
+
+} // namespace Bugzilla_51912
Index: clang-tools-extra/clang-tidy/cppcoreguidelines/VirtualClassDestructorCheck.cpp
===
--- clang-tools-extra/clang-tidy/cppcoreguidelines/VirtualClassDestructorCheck.cpp
+++ clang-tools-extra/clang-tidy/cppcoreguidelines/VirtualClassDestructorCheck.cpp
@@ -19,6 +19,21 @@
 namespace tidy {
 namespace cppcoreguidelines {
 
+AST_MATCHER(CXXRecordDecl, hasPublicVirtualOrProtectedNonVirtualDestructor) {
+  // We need to call Node.getDestructor() instead of matching a
+  // CXXDestructorDecl. Otherwise, tests will fail for class templates, since
+  // 

[PATCH] D95168: [clang-format] Add InsertBraces option

2021-10-05 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

This will fail in the presence of macro line concatination

  if (x)
  return true;
  else
  return false;
  
  #define RETURN(x) \
  if (x) \
  return true;\
  else \
   return false;

it will remove the trailing \

  if (x) {
return true;
  } else {
return false;
  }
  
  #define RETURN(x) 
 \
if (x) {
 \
  return true;
  }
  else {
return false;
  }


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95168

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


[PATCH] D111124: [Clang][OpenMP] Allow loop-transformations with template parameters.

2021-10-05 Thread Michael Kruse via Phabricator via cfe-commits
Meinersbur created this revision.
Meinersbur added reviewers: ABataev, jdenny.
Meinersbur added projects: OpenMP, clang.
Herald added subscribers: zzheng, guansong, yaxunl.
Meinersbur requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added a subscriber: sstefan1.

Clang would reject

  #pragma omp for
  #pragma omp tile sizes(P)
  for (int i = 0; i < 128; ++i) {}

where P is a template parameter, but the loop itself is not template-dependent. 
Because P context-dependent, the TransformedStmt cannot be generated and 
therefore nullptr (until the template is instantiated). The OMPForDirective 
would still expect the a loop is the dependent context and trigger an error.

Fix by introducing a NumGeneratedLoops field to OMPLoopTransformation. This is 
used to distinguish the case where no TransformedStmt will be generated at all 
(e.g. `#pragma omp unroll full`) and template instantiation is needed. In the 
later case, delay resolving the iteration space like when the for-loop itself 
is template-dependent until the template instatiation.

A more radical solution would always delay the iteration space analysis until 
template instantiation, but would also break many test cases.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D24

Files:
  clang/include/clang/AST/StmtOpenMP.h
  clang/lib/AST/StmtOpenMP.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/test/OpenMP/tile_ast_print.cpp
  clang/test/OpenMP/unroll_ast_print.cpp

Index: clang/test/OpenMP/unroll_ast_print.cpp
===
--- clang/test/OpenMP/unroll_ast_print.cpp
+++ clang/test/OpenMP/unroll_ast_print.cpp
@@ -124,4 +124,26 @@
   unroll_templated();
 }
 
+
+// PRINT-LABEL: template  void unroll_templated_factor(int start, int stop, int step) {
+// DUMP-LABEL:  FunctionTemplateDecl {{.*}} unroll_templated_factor
+template 
+void unroll_templated_factor(int start, int stop, int step) {
+  // PRINT: #pragma omp unroll partial(Factor)
+  // DUMP:  OMPUnrollDirective
+  // DUMP-NEXT: OMPPartialClause
+  // DUMP-NEXT:   DeclRefExpr {{.*}} 'Factor' 'int'
+  #pragma omp unroll partial(Factor)
+// PRINT-NEXT: for (int i = start; i < stop; i += step)
+// DUMP-NEXT:  ForStmt
+for (int i = start; i < stop; i += step)
+  // PRINT-NEXT: body(i);
+  // DUMP:  CallExpr
+  body(i);
+}
+void unroll_template_factor() {
+  unroll_templated_factor<4>(0, 42, 2);
+}
+
+
 #endif
Index: clang/test/OpenMP/tile_ast_print.cpp
===
--- clang/test/OpenMP/tile_ast_print.cpp
+++ clang/test/OpenMP/tile_ast_print.cpp
@@ -162,4 +162,25 @@
 }
 
 
+// PRINT-LABEL: template  void foo7(int start, int stop, int step) {
+// DUMP-LABEL: FunctionTemplateDecl {{.*}} foo7
+template 
+void foo7(int start, int stop, int step) {
+  // PRINT: #pragma omp tile sizes(Tile)
+  // DUMP:  OMPTileDirective
+  // DUMP-NEXT:   OMPSizesClause
+  // DUMP-NEXT: DeclRefExpr {{.*}} 'Tile' 'int'
+  #pragma omp tile sizes(Tile)
+// PRINT-NEXT:  for (int i = start; i < stop; i += step)
+// DUMP-NEXT: ForStmt
+for (int i = start; i < stop; i += step)
+  // PRINT-NEXT: body(i);
+  // DUMP:  CallExpr
+  body(i);
+}
+void tfoo7() {
+  foo7<5>(0, 42, 2);
+}
+
+
 #endif
Index: clang/lib/Serialization/ASTWriterStmt.cpp
===
--- clang/lib/Serialization/ASTWriterStmt.cpp
+++ clang/lib/Serialization/ASTWriterStmt.cpp
@@ -2227,6 +2227,7 @@
 void ASTStmtWriter::VisitOMPLoopTransformationDirective(
 OMPLoopTransformationDirective *D) {
   VisitOMPLoopBasedDirective(D);
+  Record.writeUInt32(D->getNumGeneratedLoops());
 }
 
 void ASTStmtWriter::VisitOMPTileDirective(OMPTileDirective *D) {
Index: clang/lib/Serialization/ASTReaderStmt.cpp
===
--- clang/lib/Serialization/ASTReaderStmt.cpp
+++ clang/lib/Serialization/ASTReaderStmt.cpp
@@ -2327,6 +2327,7 @@
 void ASTStmtReader::VisitOMPLoopTransformationDirective(
 OMPLoopTransformationDirective *D) {
   VisitOMPLoopBasedDirective(D);
+  D->setNumGeneratedLoops(Record.readUInt32());
 }
 
 void ASTStmtReader::VisitOMPTileDirective(OMPTileDirective *D) {
Index: clang/lib/Sema/SemaOpenMP.cpp
===
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -12919,10 +12919,12 @@
   Body, OriginalInits))
 return StmtError();
 
+  unsigned NumGeneratedLoops = PartialClause ? 1 : 0;
+
   // Delay unrolling to when template is completely instantiated.
   if (CurContext->isDependentContext())
 return OMPUnrollDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt,
-  nullptr, nullptr);
+   

[PATCH] D110925: [clangd] Follow-up on rGdea48079b90d

2021-10-05 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: llvm/include/llvm/Support/FileSystem/UniqueID.h:17
 
+#include "llvm/ADT/DenseMap.h"
 #include 

kbobyrev wrote:
> sammccall wrote:
> > you only need DenseMapInfo here
> I think I do need utility because I'm using `std::pair`
I meant this file can include DenseMapInfo.h instead of DenseMap.h. Fixed in 
4e91035387faf9e18134b1d46ce0fa803a6e9122


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110925

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


Re: [PATCH] D110925: [clangd] Follow-up on rGdea48079b90d

2021-10-05 Thread Kirill Bobyrev via cfe-commits
Ahh, sorry, I thought you meant the other one :( Apologies for confusion

On Tue, Oct 5, 2021 at 9:58 AM Sam McCall via Phabricator <
revi...@reviews.llvm.org> wrote:

> sammccall added inline comments.
>
>
> 
> Comment at: llvm/include/llvm/Support/FileSystem/UniqueID.h:17
>
> +#include "llvm/ADT/DenseMap.h"
>  #include 
> 
> kbobyrev wrote:
> > sammccall wrote:
> > > you only need DenseMapInfo here
> > I think I do need utility because I'm using `std::pair`
> I meant this file can include DenseMapInfo.h instead of DenseMap.h. Fixed
> in 4e91035387faf9e18134b1d46ce0fa803a6e9122
>
>
> Repository:
>   rG LLVM Github Monorepo
>
> CHANGES SINCE LAST ACTION
>   https://reviews.llvm.org/D110925/new/
>
> https://reviews.llvm.org/D110925
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D110925: [clangd] Follow-up on rGdea48079b90d

2021-10-05 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

In D110925#3041807 , @kbobyrev wrote:

> Ahh, sorry, I thought you meant the other one :( Apologies for confusion

All good. Instead of relying on us to spot this stuff, we should probably build 
some tooling to tell us which includes are needed and which are not.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110925

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


[PATCH] D106044: [RISCV] Update to vlm.v and vsm.v according to v1.0-rc1.

2021-10-05 Thread Fraser Cormack via Phabricator via cfe-commits
frasercrmck accepted this revision.
frasercrmck added a comment.

LGTM in principle but `aliases.s` is apparently failing with something that 
looks relevant.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106044

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


[PATCH] D111039: [clangd] Include refs of base method in refs for derived method.

2021-10-05 Thread Utkarsh Saxena via Phabricator via cfe-commits
usaxena95 updated this revision to Diff 377111.
usaxena95 marked 3 inline comments as done.
usaxena95 added a comment.

Addressed comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111039

Files:
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/unittests/XRefsTests.cpp


Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -1780,11 +1780,12 @@
 AllOf(RangeIs(R), AttrsAre(ReferencesResult::Declaration |
ReferencesResult::Definition |
ReferencesResult::Override)));
-  EXPECT_THAT(
-  findReferences(AST, T.point(), 0, UseIndex ? TU.index().get() : nullptr)
-  .References,
-  UnorderedElementsAreArray(ExpectedLocations))
-  << Test;
+  for (const auto &P : T.points())
+EXPECT_THAT(findReferences(AST, P, 0, UseIndex ? TU.index().get() : 
nullptr)
+.References,
+UnorderedElementsAreArray(ExpectedLocations))
+<< "Failed for Refs at " << P << "\n"
+<< Test;
 }
 
 TEST(FindReferences, WithinAST) {
@@ -1961,7 +1962,7 @@
   R"cpp(
 class Base {
 public:
-  virtual void $decl[[f^unc]]() = 0;
+  virtu^al void $decl[[f^unc]]() ^= ^0;
 };
 class Derived : public Base {
 public:
@@ -1990,13 +1991,13 @@
 };
 class Derived : public Base {
 public:
-  void $decl[[fu^nc]]() override;
+  void $decl[[fu^nc]]() over^ride;
 };
 void test(BaseBase* BB, Base* B, Derived* D) {
   // refs to overridden methods in complete type hierarchy are 
reported.
   BB->[[func]]();
   B->[[func]]();
-  D->[[func]]();
+  D->[[fu^nc]]();
 })cpp";
   checkFindRefs(Test, /*UseIndex=*/true);
 }
Index: clang-tools-extra/clangd/XRefs.cpp
===
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -1392,10 +1392,8 @@
 // references to all overridden methods in complete type hierarchy.
 if (const auto *CMD = llvm::dyn_cast(ND)) {
   if (CMD->isVirtual())
-if (IdentifierAtCursor && SM.getSpellingLoc(CMD->getLocation()) ==
-  IdentifierAtCursor->location()) {
-  if (auto ID = getSymbolID(CMD))
-OverriddenBy.Subjects.insert(ID);
+if (auto ID = getSymbolID(CMD)) {
+  OverriddenBy.Subjects.insert(ID);
   getOverriddenMethods(CMD, OverriddenMethods);
 }
 }


Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -1780,11 +1780,12 @@
 AllOf(RangeIs(R), AttrsAre(ReferencesResult::Declaration |
ReferencesResult::Definition |
ReferencesResult::Override)));
-  EXPECT_THAT(
-  findReferences(AST, T.point(), 0, UseIndex ? TU.index().get() : nullptr)
-  .References,
-  UnorderedElementsAreArray(ExpectedLocations))
-  << Test;
+  for (const auto &P : T.points())
+EXPECT_THAT(findReferences(AST, P, 0, UseIndex ? TU.index().get() : nullptr)
+.References,
+UnorderedElementsAreArray(ExpectedLocations))
+<< "Failed for Refs at " << P << "\n"
+<< Test;
 }
 
 TEST(FindReferences, WithinAST) {
@@ -1961,7 +1962,7 @@
   R"cpp(
 class Base {
 public:
-  virtual void $decl[[f^unc]]() = 0;
+  virtu^al void $decl[[f^unc]]() ^= ^0;
 };
 class Derived : public Base {
 public:
@@ -1990,13 +1991,13 @@
 };
 class Derived : public Base {
 public:
-  void $decl[[fu^nc]]() override;
+  void $decl[[fu^nc]]() over^ride;
 };
 void test(BaseBase* BB, Base* B, Derived* D) {
   // refs to overridden methods in complete type hierarchy are reported.
   BB->[[func]]();
   B->[[func]]();
-  D->[[func]]();
+  D->[[fu^nc]]();
 })cpp";
   checkFindRefs(Test, /*UseIndex=*/true);
 }
Index: clang-tools-extra/clangd/XRefs.cpp
===
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -1392,10 +1392,8 @@
 // references to all overridden methods in complete type hierarchy.
 if (const auto *CMD = llvm::dyn_cast(ND)) {
   if (CMD->isVirtual())
-if (Iden

[PATCH] D108194: [clangd] IncludeCleaner: Mark used headers

2021-10-05 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 377112.
kbobyrev added a comment.

Rebase on top of landed patches.

Ping, @sammccall


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108194

Files:
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/IncludeCleaner.h
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/ParsedAST.h
  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
@@ -16,6 +16,8 @@
 namespace clangd {
 namespace {
 
+using ::testing::UnorderedElementsAre;
+
 TEST(IncludeCleaner, ReferencedLocations) {
   struct TestCase {
 std::string HeaderCode;
@@ -131,6 +133,42 @@
   }
 }
 
+TEST(IncludeCleaner, GetUnusedHeaders) {
+  llvm::StringLiteral MainFile = R"cpp(
+#include "a.h"
+#include "b.h"
+#include "dir/c.h"
+#include "dir/unused.h"
+#include "unused.h"
+void foo() {
+  a();
+  b();
+  c();
+})cpp";
+  // Build expected ast with symbols coming from headers.
+  TestTU TU;
+  TU.Filename = "foo.cpp";
+  TU.AdditionalFiles["foo.h"] = "void foo();";
+  TU.AdditionalFiles["a.h"] = "void a();";
+  TU.AdditionalFiles["b.h"] = "void b();";
+  TU.AdditionalFiles["dir/c.h"] = "void c();";
+  TU.AdditionalFiles["unused.h"] = "void unused();";
+  TU.AdditionalFiles["dir/unused.h"] = "void dirUnused();";
+  TU.AdditionalFiles["not_included.h"] = "void notIncluded();";
+  TU.ExtraArgs = {"-I" + testPath("dir")};
+  TU.Code = MainFile.str();
+  ParsedAST AST = TU.build();
+  auto UnusedIncludes = AST.computeUnusedIncludes();
+  std::vector UnusedHeaders;
+  UnusedHeaders.reserve(UnusedIncludes.size());
+  for (const auto &Include : UnusedIncludes) {
+// Strip enclosing "".
+UnusedHeaders.push_back(
+Include.Written.substr(1, Include.Written.size() - 2));
+  }
+  EXPECT_THAT(UnusedHeaders, UnorderedElementsAre("unused.h", "dir/unused.h"));
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/ParsedAST.h
===
--- clang-tools-extra/clangd/ParsedAST.h
+++ clang-tools-extra/clangd/ParsedAST.h
@@ -118,6 +118,8 @@
 return Resolver.get();
   }
 
+  std::vector computeUnusedIncludes();
+
 private:
   ParsedAST(llvm::StringRef Version,
 std::shared_ptr Preamble,
Index: clang-tools-extra/clangd/ParsedAST.cpp
===
--- clang-tools-extra/clangd/ParsedAST.cpp
+++ clang-tools-extra/clangd/ParsedAST.cpp
@@ -18,6 +18,7 @@
 #include "FeatureModule.h"
 #include "Headers.h"
 #include "HeuristicResolver.h"
+#include "IncludeCleaner.h"
 #include "IncludeFixer.h"
 #include "Preamble.h"
 #include "SourceCode.h"
@@ -624,5 +625,31 @@
 return llvm::None;
   return llvm::StringRef(Preamble->Version);
 }
+
+std::vector ParsedAST::computeUnusedIncludes() {
+  const auto &SM = getSourceManager();
+
+  auto Refs = findReferencedLocations(*this);
+  auto ReferencedFileIDs = findReferencedFiles(Refs, SM);
+  llvm::DenseSet ReferencedFiles;
+  ReferencedFiles.reserve(ReferencedFileIDs.size());
+  for (FileID FID : ReferencedFileIDs) {
+const FileEntry *FE = SM.getFileEntryForID(FID);
+if (!FE) {
+  elog("Missing FE for {0}", SM.getComposedLoc(FID, 0).printToString(SM));
+  continue;
+}
+const auto File = Includes.getID(FE);
+if (!File) {
+  elog("Missing FE for {0}", SM.getComposedLoc(FID, 0).printToString(SM));
+  continue;
+}
+ReferencedFiles.insert(*File);
+  }
+  auto MainFileIndex = Includes.getID(SM.getFileEntryForID(SM.getMainFileID()));
+  assert(MainFileIndex && "MainFile should always have HeaderID (0)");
+  return getUnused(*MainFileIndex, Includes, ReferencedFiles, SM);
+}
+
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/IncludeCleaner.h
===
--- clang-tools-extra/clangd/IncludeCleaner.h
+++ clang-tools-extra/clangd/IncludeCleaner.h
@@ -25,6 +25,7 @@
 #include "ParsedAST.h"
 #include "clang/Basic/SourceLocation.h"
 #include "llvm/ADT/DenseSet.h"
+#include 
 
 namespace clang {
 namespace clangd {
@@ -46,6 +47,31 @@
 /// - err on the side of reporting all possible locations
 ReferencedLocations findReferencedLocations(ParsedAST &AST);
 
+/// Retrieves IDs of all files containing SourceLocations from \p Locs.
+/// FIXME: Those locations could be within macro expansions and are resolved to
+/// their spelling/expansion locations.
+llvm::DenseSet findReferencedFiles(const ReferencedLocations &Locs,
+   const SourceManager &SM);
+
+inlin

[PATCH] D111039: [clangd] Include refs of base method in refs for derived method.

2021-10-05 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, lgtm!




Comment at: clang-tools-extra/clangd/XRefs.cpp:1397
+  OverriddenBy.Subjects.insert(ID);
   getOverriddenMethods(CMD, OverriddenMethods);
 }

note that there's a behaviour change here as well. not sure how often it 
matters in practice, but previously we would still get the overriden methods 
for a symbol even if we fail to generate symbolid for it. let's keep it the 
same.



Comment at: clang-tools-extra/clangd/unittests/XRefsTests.cpp:1783
ReferencesResult::Override)));
-  EXPECT_THAT(
-  findReferences(AST, T.point(), 0, UseIndex ? TU.index().get() : nullptr)
-  .References,
-  UnorderedElementsAreArray(ExpectedLocations))
-  << Test;
+  for (const auto &P : T.points())
+EXPECT_THAT(findReferences(AST, P, 0, UseIndex ? TU.index().get() : 
nullptr)

nit: I'd add braces here, even though this is still a single statement, it 
spans multiple lines and becomes confusing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111039

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


[PATCH] D108194: [clangd] IncludeCleaner: Mark used headers

2021-10-05 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Sorry, I thought i'd sent these comments...




Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:158
+
+std::vector
+getUnused(IncludeStructure::HeaderID EntryPoint,

Why are we passing around Inclusions by value?



Comment at: clang-tools-extra/clangd/IncludeCleaner.h:51
+/// Retrieves IDs of all files containing SourceLocations from \p Locs.
+/// FIXME: Those locations could be within macro expansions and are resolved to
+/// their spelling/expansion locations.

This says FIXME but IIUC it's fixed.



Comment at: clang-tools-extra/clangd/IncludeCleaner.h:56
+
+inline llvm::DenseMap 
directlyReferencedFiles(
+const IncludeStructure &Includes,

this function is undocumented, unused and untested :-)

What's it for? Why does it not return a set?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108194

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


[PATCH] D111039: [clangd] Include refs of base method in refs for derived method.

2021-10-05 Thread Utkarsh Saxena via Phabricator via cfe-commits
usaxena95 updated this revision to Diff 377114.
usaxena95 marked an inline comment as done.
usaxena95 added a comment.

Addressed comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111039

Files:
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/unittests/XRefsTests.cpp


Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -1780,11 +1780,13 @@
 AllOf(RangeIs(R), AttrsAre(ReferencesResult::Declaration |
ReferencesResult::Definition |
ReferencesResult::Override)));
-  EXPECT_THAT(
-  findReferences(AST, T.point(), 0, UseIndex ? TU.index().get() : nullptr)
-  .References,
-  UnorderedElementsAreArray(ExpectedLocations))
-  << Test;
+  for (const auto &P : T.points()) {
+EXPECT_THAT(findReferences(AST, P, 0, UseIndex ? TU.index().get() : 
nullptr)
+.References,
+UnorderedElementsAreArray(ExpectedLocations))
+<< "Failed for Refs at " << P << "\n"
+<< Test;
+  }
 }
 
 TEST(FindReferences, WithinAST) {
@@ -1961,7 +1963,7 @@
   R"cpp(
 class Base {
 public:
-  virtual void $decl[[f^unc]]() = 0;
+  virtu^al void $decl[[f^unc]]() ^= ^0;
 };
 class Derived : public Base {
 public:
@@ -1990,13 +1992,13 @@
 };
 class Derived : public Base {
 public:
-  void $decl[[fu^nc]]() override;
+  void $decl[[fu^nc]]() over^ride;
 };
 void test(BaseBase* BB, Base* B, Derived* D) {
   // refs to overridden methods in complete type hierarchy are 
reported.
   BB->[[func]]();
   B->[[func]]();
-  D->[[func]]();
+  D->[[fu^nc]]();
 })cpp";
   checkFindRefs(Test, /*UseIndex=*/true);
 }
Index: clang-tools-extra/clangd/XRefs.cpp
===
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -1391,13 +1391,11 @@
 // Special case: For virtual methods, report decl/def of overrides and
 // references to all overridden methods in complete type hierarchy.
 if (const auto *CMD = llvm::dyn_cast(ND)) {
-  if (CMD->isVirtual())
-if (IdentifierAtCursor && SM.getSpellingLoc(CMD->getLocation()) ==
-  IdentifierAtCursor->location()) {
-  if (auto ID = getSymbolID(CMD))
-OverriddenBy.Subjects.insert(ID);
-  getOverriddenMethods(CMD, OverriddenMethods);
-}
+  if (CMD->isVirtual()) {
+if (auto ID = getSymbolID(CMD))
+  OverriddenBy.Subjects.insert(ID);
+getOverriddenMethods(CMD, OverriddenMethods);
+  }
 }
   }
 }


Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -1780,11 +1780,13 @@
 AllOf(RangeIs(R), AttrsAre(ReferencesResult::Declaration |
ReferencesResult::Definition |
ReferencesResult::Override)));
-  EXPECT_THAT(
-  findReferences(AST, T.point(), 0, UseIndex ? TU.index().get() : nullptr)
-  .References,
-  UnorderedElementsAreArray(ExpectedLocations))
-  << Test;
+  for (const auto &P : T.points()) {
+EXPECT_THAT(findReferences(AST, P, 0, UseIndex ? TU.index().get() : nullptr)
+.References,
+UnorderedElementsAreArray(ExpectedLocations))
+<< "Failed for Refs at " << P << "\n"
+<< Test;
+  }
 }
 
 TEST(FindReferences, WithinAST) {
@@ -1961,7 +1963,7 @@
   R"cpp(
 class Base {
 public:
-  virtual void $decl[[f^unc]]() = 0;
+  virtu^al void $decl[[f^unc]]() ^= ^0;
 };
 class Derived : public Base {
 public:
@@ -1990,13 +1992,13 @@
 };
 class Derived : public Base {
 public:
-  void $decl[[fu^nc]]() override;
+  void $decl[[fu^nc]]() over^ride;
 };
 void test(BaseBase* BB, Base* B, Derived* D) {
   // refs to overridden methods in complete type hierarchy are reported.
   BB->[[func]]();
   B->[[func]]();
-  D->[[func]]();
+  D->[[fu^nc]]();
 })cpp";
   checkFindRefs(Test, /*UseIndex=*/true);
 }
Index: clang-tools-extra/clangd/XRefs.cpp
===
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/X

[PATCH] D111039: [clangd] Include refs of base method in refs for derived method.

2021-10-05 Thread Utkarsh Saxena via Phabricator via cfe-commits
usaxena95 marked an inline comment as done.
usaxena95 added inline comments.



Comment at: clang-tools-extra/clangd/XRefs.cpp:1397
+  OverriddenBy.Subjects.insert(ID);
   getOverriddenMethods(CMD, OverriddenMethods);
 }

kadircet wrote:
> note that there's a behaviour change here as well. not sure how often it 
> matters in practice, but previously we would still get the overriden methods 
> for a symbol even if we fail to generate symbolid for it. let's keep it the 
> same.
Hmm. You are right. Even in `getOverriddenMethods` we find the symbolID 
*optionally* and we always traverse the complete type hierarchy. Let's do the 
same here for consistency.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111039

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


[PATCH] D108482: [Clang] Fix instantiation of OpaqueValueExprs (Bug #45964)

2021-10-05 Thread Raul Tambre via Phabricator via cfe-commits
tambre added a comment.

In D108482#3041127 , @ricejasonf 
wrote:

> I rebased onto `main` and made one small style fix. I don't think the rebase 
> changes anything.
>
> I do not understand why random things are failing in the CI. Even on my own 
> build machine with a fresh build directory CMake fails with errors about 
> unregistered files in ExecutionEngine/Orc.
>
> All this stuff is completely unrelated to my very minor change. Is there 
> something about the process that I am missing?

CI looks clean to me except for the Flang failure, which seems to have been 
reverted 
.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108482

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


[PATCH] D108482: [Clang] Fix instantiation of OpaqueValueExprs (Bug #45964)

2021-10-05 Thread Raul Tambre via Phabricator via cfe-commits
tambre added inline comments.



Comment at: clang/test/CodeGenCXX/pr45964-decomp-transform.cpp:1
+// RUN: %clang_cc1 -std=c++1z -triple x86_64-linux-gnu -emit-llvm -o - %s | 
FileCheck %s
+

I'd prefer `-std=c++17` since the standard and flag have been finalized.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108482

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


[PATCH] D110823: [clangd] Add code completion of param name on /* inside function calls.

2021-10-05 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/CodeComplete.cpp:1148
+  std::set ParamNamesSeen;
+}; // SignatureHelpCollector
+

change the ending comment (well, I'd actually drop it completely)



Comment at: clang-tools-extra/clangd/CodeComplete.cpp:1927
+  {FileName, Offset, *Preamble,
+   PreamblePatch::createFullPatch(FileName, ParseInput, *Preamble),
+   ParseInput});

i think it's subtle that we require a fullpatch here. maybe put a comment 
saying that "we want to see signatures coming from newly introduced includes, 
hence a full patch".



Comment at: clang-tools-extra/clangd/CodeComplete.cpp:1956
+  auto Content = llvm::StringRef(ParseInput.Contents).take_front(*Offset);
+  if (Content.endswith("/*")) {
+// We are doing code completion of a comment, where we currently only

what if the user triggers at `foo(/*  b^`? I think we'd still want to provide 
`bar`.

I think we should detect whether we're in a comment first, we can run the Lexer 
for that but it'd probably be an overkill. For now I think we can just check 
for the string after last `*/`, if it has a `/*` we're in a comment, otherwise 
we check for the current line only. if it has a `//` we're again in a comment.

Then we can switch to the `codeCompleteComment` mode, inside there one branch 
can collect completion results for possible parameter names (while filtering 
using the currently typed text) and we can expand with more logic later on 
(e.g. suggest identifiers from index?).

WDYT?



Comment at: clang-tools-extra/clangd/CodeComplete.cpp:1963
+auto OffsetBeforeComment = *Offset - 2;
+return codeCompleteComment(FileName, OffsetBeforeComment, Preamble,
+   ParseInput);

i think we should propagate `Opts` here and then override the pieces 
accordingly.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110823

___
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-10-05 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov added a comment.

Gentle ping.


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] D108194: [clangd] IncludeCleaner: Mark used headers

2021-10-05 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 377125.
kbobyrev marked 3 inline comments as done.
kbobyrev added a comment.

Resolve review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108194

Files:
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/IncludeCleaner.h
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/ParsedAST.h
  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
@@ -16,6 +16,8 @@
 namespace clangd {
 namespace {
 
+using ::testing::UnorderedElementsAre;
+
 TEST(IncludeCleaner, ReferencedLocations) {
   struct TestCase {
 std::string HeaderCode;
@@ -131,6 +133,42 @@
   }
 }
 
+TEST(IncludeCleaner, GetUnusedHeaders) {
+  llvm::StringLiteral MainFile = R"cpp(
+#include "a.h"
+#include "b.h"
+#include "dir/c.h"
+#include "dir/unused.h"
+#include "unused.h"
+void foo() {
+  a();
+  b();
+  c();
+})cpp";
+  // Build expected ast with symbols coming from headers.
+  TestTU TU;
+  TU.Filename = "foo.cpp";
+  TU.AdditionalFiles["foo.h"] = "void foo();";
+  TU.AdditionalFiles["a.h"] = "void a();";
+  TU.AdditionalFiles["b.h"] = "void b();";
+  TU.AdditionalFiles["dir/c.h"] = "void c();";
+  TU.AdditionalFiles["unused.h"] = "void unused();";
+  TU.AdditionalFiles["dir/unused.h"] = "void dirUnused();";
+  TU.AdditionalFiles["not_included.h"] = "void notIncluded();";
+  TU.ExtraArgs = {"-I" + testPath("dir")};
+  TU.Code = MainFile.str();
+  ParsedAST AST = TU.build();
+  auto UnusedIncludes = AST.computeUnusedIncludes();
+  std::vector UnusedHeaders;
+  UnusedHeaders.reserve(UnusedIncludes.size());
+  for (const auto &Include : UnusedIncludes) {
+// Strip enclosing "".
+UnusedHeaders.push_back(
+Include->Written.substr(1, Include->Written.size() - 2));
+  }
+  EXPECT_THAT(UnusedHeaders, UnorderedElementsAre("unused.h", "dir/unused.h"));
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/ParsedAST.h
===
--- clang-tools-extra/clangd/ParsedAST.h
+++ clang-tools-extra/clangd/ParsedAST.h
@@ -118,6 +118,8 @@
 return Resolver.get();
   }
 
+  std::vector computeUnusedIncludes();
+
 private:
   ParsedAST(llvm::StringRef Version,
 std::shared_ptr Preamble,
Index: clang-tools-extra/clangd/ParsedAST.cpp
===
--- clang-tools-extra/clangd/ParsedAST.cpp
+++ clang-tools-extra/clangd/ParsedAST.cpp
@@ -18,6 +18,7 @@
 #include "FeatureModule.h"
 #include "Headers.h"
 #include "HeuristicResolver.h"
+#include "IncludeCleaner.h"
 #include "IncludeFixer.h"
 #include "Preamble.h"
 #include "SourceCode.h"
@@ -624,5 +625,31 @@
 return llvm::None;
   return llvm::StringRef(Preamble->Version);
 }
+
+std::vector ParsedAST::computeUnusedIncludes() {
+  const auto &SM = getSourceManager();
+
+  auto Refs = findReferencedLocations(*this);
+  auto ReferencedFileIDs = findReferencedFiles(Refs, SM);
+  llvm::DenseSet ReferencedFiles;
+  ReferencedFiles.reserve(ReferencedFileIDs.size());
+  for (FileID FID : ReferencedFileIDs) {
+const FileEntry *FE = SM.getFileEntryForID(FID);
+if (!FE) {
+  elog("Missing FE for {0}", SM.getComposedLoc(FID, 0).printToString(SM));
+  continue;
+}
+const auto File = Includes.getID(FE);
+if (!File) {
+  elog("Missing FE for {0}", SM.getComposedLoc(FID, 0).printToString(SM));
+  continue;
+}
+ReferencedFiles.insert(*File);
+  }
+  auto MainFileIndex = Includes.getID(SM.getFileEntryForID(SM.getMainFileID()));
+  assert(MainFileIndex && "MainFile should always have HeaderID (0)");
+  return getUnused(*MainFileIndex, Includes, ReferencedFiles, SM);
+}
+
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/IncludeCleaner.h
===
--- clang-tools-extra/clangd/IncludeCleaner.h
+++ clang-tools-extra/clangd/IncludeCleaner.h
@@ -25,6 +25,7 @@
 #include "ParsedAST.h"
 #include "clang/Basic/SourceLocation.h"
 #include "llvm/ADT/DenseSet.h"
+#include 
 
 namespace clang {
 namespace clangd {
@@ -46,6 +47,18 @@
 /// - err on the side of reporting all possible locations
 ReferencedLocations findReferencedLocations(ParsedAST &AST);
 
+/// Retrieves IDs of all files containing SourceLocations from \p Locs.
+llvm::DenseSet findReferencedFiles(const ReferencedLocations &Locs,
+   const SourceManager &SM);
+
+/// Retrieves headers that are referenced from the main file (\p EntryPoint)
+/// but not used.
+std::vector

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

2021-10-05 Thread Alexey Bader via Phabricator via cfe-commits
bader added inline comments.



Comment at: clang/lib/Basic/Targets/SPIR.h:59
+// translation). This mapping is enabled when the language mode is HIP.
+1, // cuda_device
+// cuda_constant pointer can be casted to default/"flat" pointer, but in

Anastasia wrote:
> bader wrote:
> > Anastasia wrote:
> > > linjamaki wrote:
> > > > bader wrote:
> > > > > keryell wrote:
> > > > > > Anastasia wrote:
> > > > > > > bader wrote:
> > > > > > > > Anastasia wrote:
> > > > > > > > > I am slightly confused as in the LLVM project those address 
> > > > > > > > > spaces are for SPIR not SPIR-V though. It is however used 
> > > > > > > > > outside of LLVM project by some tools like SPIRV-LLVM 
> > > > > > > > > Translator as a path to SPIR-V, but it has only been done as 
> > > > > > > > > a workaround since we had no SPIR-V support in the LLVM 
> > > > > > > > > project yet. And if we are adding it let's do it clean to 
> > > > > > > > > avoid/resolve any confusion.
> > > > > > > > > 
> > > > > > > > > I think we need to keep both because some vendors do 
> > > > > > > > > target/use SPIR but not SPIR-V.
> > > > > > > > > 
> > > > > > > > > So if you are interested in SPIR-V and not SPIR you should 
> > > > > > > > > probably add a new target that will make things cleaner.
> > > > > > > > > I think we need to keep both because some vendors do 
> > > > > > > > > target/use SPIR but not SPIR-V.
> > > > > > > > 
> > > > > > > > @Anastasia, could you elaborate more on the difference between 
> > > > > > > > SPIR and SPIR-V?
> > > > > > > > I would like to understand what these terms mean in the context 
> > > > > > > > of LLVM project.
> > > > > > > Their conceptual differences are just that they are two different 
> > > > > > > intermediate formats.
> > > > > > > 
> > > > > > > The important thing to highlight is that it is not impossible 
> > > > > > > that some vendors use SPIR (without using SPIR-V) even despite 
> > > > > > > the fact it has been discontinued by Khronos. 
> > > > > > > 
> > > > > > > Nobody has deprecated or discontinued SPIR in the LLVM project 
> > > > > > > yet.
> > > > > > > Their conceptual differences are just that they are two different 
> > > > > > > intermediate formats.
> > > > > > > 
> > > > > > > The important thing to highlight is that it is not impossible 
> > > > > > > that some vendors use SPIR (without using SPIR-V) even despite 
> > > > > > > the fact it has been discontinued by Khronos. 
> > > > > > > 
> > > > > > > Nobody has deprecated or discontinued SPIR in the LLVM project 
> > > > > > > yet.
> > > > > > 
> > > > > > All the official Xilinx OpenCL stack is based on legacy SPIR 
> > > > > > (encoded in LLVM 6.x IR but this is another story) and I suspect 
> > > > > > this is the case for other companies.
> > > > > > So, do not deprecate or discontinue, please. :-)
> > > > > > The important thing to highlight is that it is not impossible that 
> > > > > > some vendors use SPIR (without using SPIR-V) even despite the fact 
> > > > > > it has been discontinued by Khronos.
> > > > > > Nobody has deprecated or discontinued SPIR in the LLVM project yet.
> > > > > 
> > > > > Strictly speaking `SPIR` is not defined as an intermediate language. 
> > > > > Khronos defines `SPIR-1.2` and `SPIR-2.0` formats which are based on 
> > > > > LLVM 3.2 and LLVM 3.4 version (https://www.khronos.org/spir/). There 
> > > > > is no definition of SPIR format based on current version of LLVM IR. 
> > > > > Another note is that metadata and intrinsics emitted for OpenCL with 
> > > > > clang-14 doesn't follow neither `SPIR-1.2` nor `SPIR-2.0`.
> > > > > 
> > > > > I always think of LLVM IR as leaving thing that is subject to change 
> > > > > by LLVM community, so tools working with LLVM IR must adjust to the 
> > > > > particular version (e.g. release version like LLVM 13 or ToT). We 
> > > > > apply this logic to SPIRV-LLVM-Translator tool and update it 
> > > > > according to LLVM format changes (e.g. kernel argument information 
> > > > > defined in Khronos spec must be named metadata whereas clang emits 
> > > > > function metadata).
> > > > > 
> > > > > > I am slightly confused as in the LLVM project those address spaces 
> > > > > > are for SPIR not SPIR-V though.
> > > > > [skip]
> > > > > > Their conceptual differences are just that they are two different 
> > > > > > intermediate formats.
> > > > > 
> > > > > If this is the only difference, I don't think it a good idea to 
> > > > > create another LLVM target to separate SPIR and SPIR-V. From my point 
> > > > > of view it creates logic ambiguity and code duplication with no 
> > > > > additional value. @Anastasia, what problems do you see if we continue 
> > > > > treating LLVM IR with spir* target triple as LLVM IR representation 
> > > > > of SPIR-V format?
> > > > The state of SPIR 1.2/2.0 in Clang seems to be that the SPIR target has 
> > > > transformed to mean “SPIR 1.2/2.0 derivative”, but that do

[PATCH] D109144: [SPIR-V] Add SPIR-V triple architecture and clang target info

2021-10-05 Thread Alexey Bader via Phabricator via cfe-commits
bader added a comment.

In D109144#3032865 , @Anastasia wrote:

> It would be good to get closure on this asap.
>
> @bader We had related discussions on the other reviews about the approach in 
> this patch. If you have any concerns/suggestions can you please notify asap...

Sorry for the delay. I was on vacation last week. I've added my concerns to the 
discussion in https://reviews.llvm.org/D108621.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109144

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


[PATCH] D109517: [Clang][ARM][AArch64] Add support for Armv9-A, Armv9.1-A and Armv9.2-A

2021-10-05 Thread Victor Campos via Phabricator via cfe-commits
vhscampos added a comment.

To the relevant persons I have just added to the review: @srhines 
@nickdesaulniers @llozano

The cryptographic extensions will **//NOT//** be enabled by default on Armv9-A 
and on Armv9-A ARM CPUs.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109517

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


[clang] e463b69 - [Support] Change fatal_error_handler_t to take a const char* instead of std::string

2021-10-05 Thread Simon Pilgrim via cfe-commits

Author: Simon Pilgrim
Date: 2021-10-05T10:55:40+01:00
New Revision: e463b69736da8b0a950ecd937cf990401bdfcdeb

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

LOG: [Support] Change fatal_error_handler_t to take a const char* instead of 
std::string

https://commondatastorage.googleapis.com/chromium-browser-clang/llvm-include-analysis.html

Excessive use of the  header has a massive impact on compile time; its 
most commonly included via the ErrorHandling.h header, which has to be included 
in many key headers, impacting many source files that have no need for 
std::string.

As an initial step toward removing the  include from ErrorHandling.h, 
this patch proposes to update the fatal_error_handler_t handler to just take a 
raw const char* instead.

The next step will be to remove the report_fatal_error std::string variant, 
which will involve a lot of cleanup and better use of Twine/StringRef.

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

Added: 


Modified: 
clang/tools/clang-repl/ClangRepl.cpp
clang/tools/driver/cc1_main.cpp
clang/tools/driver/cc1as_main.cpp
clang/tools/libclang/FatalErrorHandler.cpp
llvm/include/llvm/Support/ErrorHandling.h
llvm/lib/Support/ErrorHandling.cpp
llvm/tools/llvm-as-fuzzer/llvm-as-fuzzer.cpp
llvm/tools/llvm-isel-fuzzer/llvm-isel-fuzzer.cpp
llvm/tools/llvm-opt-fuzzer/llvm-opt-fuzzer.cpp

Removed: 




diff  --git a/clang/tools/clang-repl/ClangRepl.cpp 
b/clang/tools/clang-repl/ClangRepl.cpp
index ba6bb11abc867..8e50418f705c2 100644
--- a/clang/tools/clang-repl/ClangRepl.cpp
+++ b/clang/tools/clang-repl/ClangRepl.cpp
@@ -32,7 +32,7 @@ static llvm::cl::list 
OptInputs(llvm::cl::Positional,
  llvm::cl::ZeroOrMore,
  llvm::cl::desc("[code to run]"));
 
-static void LLVMErrorHandler(void *UserData, const std::string &Message,
+static void LLVMErrorHandler(void *UserData, const char *Message,
  bool GenCrashDiag) {
   auto &Diags = *static_cast(UserData);
 

diff  --git a/clang/tools/driver/cc1_main.cpp b/clang/tools/driver/cc1_main.cpp
index 396d6ff529f31..13fb80fbad300 100644
--- a/clang/tools/driver/cc1_main.cpp
+++ b/clang/tools/driver/cc1_main.cpp
@@ -57,7 +57,7 @@ using namespace llvm::opt;
 // Main driver
 
//===--===//
 
-static void LLVMErrorHandler(void *UserData, const std::string &Message,
+static void LLVMErrorHandler(void *UserData, const char *Message,
  bool GenCrashDiag) {
   DiagnosticsEngine &Diags = *static_cast(UserData);
 

diff  --git a/clang/tools/driver/cc1as_main.cpp 
b/clang/tools/driver/cc1as_main.cpp
index 6549b132f6166..6816fd20e43ec 100644
--- a/clang/tools/driver/cc1as_main.cpp
+++ b/clang/tools/driver/cc1as_main.cpp
@@ -550,7 +550,7 @@ static bool ExecuteAssembler(AssemblerInvocation &Opts,
   return Failed;
 }
 
-static void LLVMErrorHandler(void *UserData, const std::string &Message,
+static void LLVMErrorHandler(void *UserData, const char *Message,
  bool GenCrashDiag) {
   DiagnosticsEngine &Diags = *static_cast(UserData);
 

diff  --git a/clang/tools/libclang/FatalErrorHandler.cpp 
b/clang/tools/libclang/FatalErrorHandler.cpp
index ef21569637f03..73864754c0655 100644
--- a/clang/tools/libclang/FatalErrorHandler.cpp
+++ b/clang/tools/libclang/FatalErrorHandler.cpp
@@ -11,11 +11,11 @@
 #include "llvm/Support/ErrorHandling.h"
 #include 
 
-static void aborting_fatal_error_handler(void *, const std::string &reason,
+static void aborting_fatal_error_handler(void *, const char *reason,
  bool) {
   // Write the result out to stderr avoiding errs() because raw_ostreams can
   // call report_fatal_error.
-  fprintf(stderr, "LIBCLANG FATAL ERROR: %s\n", reason.c_str());
+  fprintf(stderr, "LIBCLANG FATAL ERROR: %s\n", reason);
   ::abort();
 }
 

diff  --git a/llvm/include/llvm/Support/ErrorHandling.h 
b/llvm/include/llvm/Support/ErrorHandling.h
index 81cac477cb69b..260c76fadc95a 100644
--- a/llvm/include/llvm/Support/ErrorHandling.h
+++ b/llvm/include/llvm/Support/ErrorHandling.h
@@ -18,12 +18,12 @@
 #include 
 
 namespace llvm {
-class StringRef;
+  class StringRef;
   class Twine;
 
   /// An error handler callback.
   typedef void (*fatal_error_handler_t)(void *user_data,
-const std::string& reason,
+const char *reason,
 bool gen_crash_diag);
 
   /// install_fatal_error_handler - Installs a new error handler to be used

diff  --git a/llvm/lib/Support/ErrorHandling.cpp 
b/llvm/lib/Suppor

[PATCH] D111049: [Support] Change fatal_error_handler_t to take a const char* instead of std::string

2021-10-05 Thread Simon Pilgrim via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe463b69736da: [Support] Change fatal_error_handler_t to take 
a const char* instead of std… (authored by RKSimon).

Changed prior to commit:
  https://reviews.llvm.org/D111049?vs=376870&id=377135#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111049

Files:
  clang/tools/clang-repl/ClangRepl.cpp
  clang/tools/driver/cc1_main.cpp
  clang/tools/driver/cc1as_main.cpp
  clang/tools/libclang/FatalErrorHandler.cpp
  llvm/include/llvm/Support/ErrorHandling.h
  llvm/lib/Support/ErrorHandling.cpp
  llvm/tools/llvm-as-fuzzer/llvm-as-fuzzer.cpp
  llvm/tools/llvm-isel-fuzzer/llvm-isel-fuzzer.cpp
  llvm/tools/llvm-opt-fuzzer/llvm-opt-fuzzer.cpp

Index: llvm/tools/llvm-opt-fuzzer/llvm-opt-fuzzer.cpp
===
--- llvm/tools/llvm-opt-fuzzer/llvm-opt-fuzzer.cpp
+++ llvm/tools/llvm-opt-fuzzer/llvm-opt-fuzzer.cpp
@@ -170,7 +170,7 @@
   return 0;
 }
 
-static void handleLLVMFatalError(void *, const std::string &Message, bool) {
+static void handleLLVMFatalError(void *, const char *Message, bool) {
   // TODO: Would it be better to call into the fuzzer internals directly?
   dbgs() << "LLVM ERROR: " << Message << "\n"
  << "Aborting to trigger fuzzer exit handling.\n";
Index: llvm/tools/llvm-isel-fuzzer/llvm-isel-fuzzer.cpp
===
--- llvm/tools/llvm-isel-fuzzer/llvm-isel-fuzzer.cpp
+++ llvm/tools/llvm-isel-fuzzer/llvm-isel-fuzzer.cpp
@@ -107,7 +107,7 @@
   return 0;
 }
 
-static void handleLLVMFatalError(void *, const std::string &Message, bool) {
+static void handleLLVMFatalError(void *, const char *Message, bool) {
   // TODO: Would it be better to call into the fuzzer internals directly?
   dbgs() << "LLVM ERROR: " << Message << "\n"
  << "Aborting to trigger fuzzer exit handling.\n";
Index: llvm/tools/llvm-as-fuzzer/llvm-as-fuzzer.cpp
===
--- llvm/tools/llvm-as-fuzzer/llvm-as-fuzzer.cpp
+++ llvm/tools/llvm-as-fuzzer/llvm-as-fuzzer.cpp
@@ -30,7 +30,7 @@
 
 namespace {
 
-void MyFatalErrorHandler(void *user_data, const std::string& reason,
+void MyFatalErrorHandler(void *user_data, const char *reason,
  bool gen_crash_diag) {
   // Don't bother printing reason, just return to the test function,
   // since a fatal error represents a successful parse (i.e. it correctly
Index: llvm/lib/Support/ErrorHandling.cpp
===
--- llvm/lib/Support/ErrorHandling.cpp
+++ llvm/lib/Support/ErrorHandling.cpp
@@ -105,7 +105,7 @@
   }
 
   if (handler) {
-handler(handlerData, Reason.str(), GenCrashDiag);
+handler(handlerData, Reason.str().c_str(), GenCrashDiag);
   } else {
 // Blast the result out to stderr.  We don't try hard to make sure this
 // succeeds (e.g. handling EINTR) and we can't use errs() here because
@@ -218,11 +218,11 @@
 #endif
 }
 
-static void bindingsErrorHandler(void *user_data, const std::string& reason,
+static void bindingsErrorHandler(void *user_data, const char *reason,
  bool gen_crash_diag) {
   LLVMFatalErrorHandler handler =
   LLVM_EXTENSION reinterpret_cast(user_data);
-  handler(reason.c_str());
+  handler(reason);
 }
 
 void LLVMInstallFatalErrorHandler(LLVMFatalErrorHandler Handler) {
Index: llvm/include/llvm/Support/ErrorHandling.h
===
--- llvm/include/llvm/Support/ErrorHandling.h
+++ llvm/include/llvm/Support/ErrorHandling.h
@@ -18,12 +18,12 @@
 #include 
 
 namespace llvm {
-class StringRef;
+  class StringRef;
   class Twine;
 
   /// An error handler callback.
   typedef void (*fatal_error_handler_t)(void *user_data,
-const std::string& reason,
+const char *reason,
 bool gen_crash_diag);
 
   /// install_fatal_error_handler - Installs a new error handler to be used
Index: clang/tools/libclang/FatalErrorHandler.cpp
===
--- clang/tools/libclang/FatalErrorHandler.cpp
+++ clang/tools/libclang/FatalErrorHandler.cpp
@@ -11,11 +11,11 @@
 #include "llvm/Support/ErrorHandling.h"
 #include 
 
-static void aborting_fatal_error_handler(void *, const std::string &reason,
+static void aborting_fatal_error_handler(void *, const char *reason,
  bool) {
   // Write the result out to stderr avoiding errs() because raw_ostreams can
   // call report_fatal_error.
-  fprintf(stderr, "LIBCLANG FATAL ERROR: %s\n", reason.c_str());
+  fprintf(stderr, "LIBCLANG FATAL ERROR: %s\n", reason);
   ::abort();
 }
 
Index: clang/tools/driver

[PATCH] D110810: [clang][ASTImporter] Simplify code of attribute import [NFC].

2021-10-05 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 377143.
balazske added a comment.

Adding `&&` and new asserts to use `AttrImporter` only once.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110810

Files:
  clang/lib/AST/ASTImporter.cpp

Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -8453,7 +8453,8 @@
 };
 
 class AttrImporter {
-  Error Err = Error::success();
+  Error Err{Error::success()};
+  Attr *ToAttr = nullptr;
   ASTImporter &Importer;
   ASTNodeImporter NImporter;
 
@@ -8462,15 +8463,14 @@
 
   // Create an "importer" for an attribute parameter.
   // Result of the 'value()' of that object is to be passed to the function
-  // 'createImpoprtedAttr', in the order that is expected by the attribute
-  // class.
+  // 'importAttr', in the order that is expected by the attribute class.
   template  AttrArgImporter importArg(const T &From) {
 return AttrArgImporter(NImporter, Err, From);
   }
 
   // Create an "importer" for an attribute parameter that has array type.
   // Result of the 'value()' of that object is to be passed to the function
-  // 'createImpoprtedAttr', then the size of the array as next argument.
+  // 'importAttr', then the size of the array as next argument.
   template 
   AttrArgArrayImporter importArrayArg(const llvm::iterator_range &From,
  unsigned ArraySize) {
@@ -8483,10 +8483,13 @@
   // (The 'Create' with 'ASTContext' first and 'AttributeCommonInfo' last is
   // used here.) As much data is copied or imported from the old attribute
   // as possible. The passed arguments should be already imported.
+  // If an import error happens, the internal error is set to it, and any
+  // further import attempt is ignored.
   template 
-  Expected createImportedAttr(const T *FromAttr, Arg &&...ImportedArg) {
+  void importAttr(const T *FromAttr, Arg &&...ImportedArg) {
 static_assert(std::is_base_of::value,
   "T should be subclass of Attr.");
+assert(!ToAttr && "Use one AttrImporter to import one Attribute object.");
 
 const IdentifierInfo *ToAttrName = Importer.Import(FromAttr->getAttrName());
 const IdentifierInfo *ToScopeName =
@@ -8497,262 +8500,177 @@
 NImporter.importChecked(Err, FromAttr->getScopeLoc());
 
 if (Err)
-  return std::move(Err);
+  return;
 
 AttributeCommonInfo ToI(ToAttrName, ToScopeName, ToAttrRange, ToScopeLoc,
 FromAttr->getParsedKind(), FromAttr->getSyntax(),
 FromAttr->getAttributeSpellingListIndex());
 // The "SemanticSpelling" is not needed to be passed to the constructor.
 // That value is recalculated from the SpellingListIndex if needed.
-T *ToAttr = T::Create(Importer.getToContext(),
-  std::forward(ImportedArg)..., ToI);
+ToAttr = T::Create(Importer.getToContext(),
+   std::forward(ImportedArg)..., ToI);
 
 ToAttr->setImplicit(FromAttr->isImplicit());
 ToAttr->setPackExpansion(FromAttr->isPackExpansion());
 if (auto *ToInheritableAttr = dyn_cast(ToAttr))
   ToInheritableAttr->setInherited(FromAttr->isInherited());
+  }
+
+  // Create a clone of the 'FromAttr' and import its source range only.
+  // This causes objects with invalid references to be created if the 'FromAttr'
+  // contains other data that should be imported.
+  void cloneAttr(const Attr *FromAttr) {
+assert(!ToAttr && "Use one AttrImporter to import one Attribute object.");
 
+SourceRange ToRange = NImporter.importChecked(Err, FromAttr->getRange());
+if (Err)
+  return;
+
+ToAttr = FromAttr->clone(Importer.getToContext());
+ToAttr->setRange(ToRange);
+  }
+
+  // Get the result of the previous import attempt (can be used only once).
+  llvm::Expected getResult() && {
+if (Err)
+  return std::move(Err);
+assert(ToAttr && "Attribute should be created.");
 return ToAttr;
   }
 };
 
 Expected ASTImporter::Import(const Attr *FromAttr) {
-  Attr *ToAttr = nullptr;
-  // FIXME: Use AttrImporter as much as possible, try to remove the import
-  // of range from here.
-  SourceRange ToRange;
-  if (Error Err = importInto(ToRange, FromAttr->getRange()))
-return std::move(Err);
+  AttrImporter AI(*this);
 
   // FIXME: Is there some kind of AttrVisitor to use here?
   switch (FromAttr->getKind()) {
   case attr::Aligned: {
 auto *From = cast(FromAttr);
-AlignedAttr *To;
-auto CreateAlign = [&](bool IsAlignmentExpr, void *Alignment) {
-  return AlignedAttr::Create(ToContext, IsAlignmentExpr, Alignment, ToRange,
- From->getSyntax(),
- From->getSemanticSpelling());
-};
-if (From->isAlignmentExpr()) {
-  if (auto ToEOrErr = Import(F

[PATCH] D110810: [clang][ASTImporter] Simplify code of attribute import [NFC].

2021-10-05 Thread Balázs Benics via Phabricator via cfe-commits
steakhal accepted this revision.
steakhal added a comment.

I think it looks great.
Thank you for addressing this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110810

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


[clang] bcefea8 - [clang][ASTImporter] Add import of thread safety attributes.

2021-10-05 Thread Balázs Kéri via cfe-commits

Author: Balázs Kéri
Date: 2021-10-05T13:08:31+02:00
New Revision: bcefea80a40ead1e1fbec2e6fa001dd4816ca5c2

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

LOG: [clang][ASTImporter] Add import of thread safety attributes.

Attributes of "C/C++ Thread safety attributes" section in Attr.td
are added to ASTImporter. The not added attributes from this section
do not need special import handling.

Reviewed By: martong

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

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index ece9e7fc01120..3c4f196a2db89 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -8634,6 +8634,174 @@ Expected ASTImporter::Import(const Attr 
*FromAttr) {
   return ToAttrOrErr.takeError();
 break;
   }
+  case attr::AcquireCapability: {
+const auto *From = cast(FromAttr);
+AttrImporter AI(*this);
+Expected ToAttrOrErr = AI.createImportedAttr(
+From, AI.importArrayArg(From->args(), From->args_size()).value(),
+From->args_size());
+if (ToAttrOrErr)
+  ToAttr = *ToAttrOrErr;
+else
+  return ToAttrOrErr.takeError();
+break;
+  }
+  case attr::TryAcquireCapability: {
+const auto *From = cast(FromAttr);
+AttrImporter AI(*this);
+Expected ToAttrOrErr = AI.createImportedAttr(
+From, AI.importArg(From->getSuccessValue()).value(),
+AI.importArrayArg(From->args(), From->args_size()).value(),
+From->args_size());
+if (ToAttrOrErr)
+  ToAttr = *ToAttrOrErr;
+else
+  return ToAttrOrErr.takeError();
+break;
+  }
+  case attr::ReleaseCapability: {
+const auto *From = cast(FromAttr);
+AttrImporter AI(*this);
+Expected ToAttrOrErr = AI.createImportedAttr(
+From, AI.importArrayArg(From->args(), From->args_size()).value(),
+From->args_size());
+if (ToAttrOrErr)
+  ToAttr = *ToAttrOrErr;
+else
+  return ToAttrOrErr.takeError();
+break;
+  }
+  case attr::RequiresCapability: {
+const auto *From = cast(FromAttr);
+AttrImporter AI(*this);
+Expected ToAttrOrErr = AI.createImportedAttr(
+From, AI.importArrayArg(From->args(), From->args_size()).value(),
+From->args_size());
+if (ToAttrOrErr)
+  ToAttr = *ToAttrOrErr;
+else
+  return ToAttrOrErr.takeError();
+break;
+  }
+  case attr::GuardedBy: {
+const auto *From = cast(FromAttr);
+AttrImporter AI(*this);
+Expected ToAttrOrErr =
+AI.createImportedAttr(From, AI.importArg(From->getArg()).value());
+if (ToAttrOrErr)
+  ToAttr = *ToAttrOrErr;
+else
+  return ToAttrOrErr.takeError();
+break;
+  }
+  case attr::PtGuardedBy: {
+const auto *From = cast(FromAttr);
+AttrImporter AI(*this);
+Expected ToAttrOrErr =
+AI.createImportedAttr(From, AI.importArg(From->getArg()).value());
+if (ToAttrOrErr)
+  ToAttr = *ToAttrOrErr;
+else
+  return ToAttrOrErr.takeError();
+break;
+  }
+  case attr::AcquiredAfter: {
+const auto *From = cast(FromAttr);
+AttrImporter AI(*this);
+Expected ToAttrOrErr = AI.createImportedAttr(
+From, AI.importArrayArg(From->args(), From->args_size()).value(),
+From->args_size());
+if (ToAttrOrErr)
+  ToAttr = *ToAttrOrErr;
+else
+  return ToAttrOrErr.takeError();
+break;
+  }
+  case attr::AcquiredBefore: {
+const auto *From = cast(FromAttr);
+AttrImporter AI(*this);
+Expected ToAttrOrErr = AI.createImportedAttr(
+From, AI.importArrayArg(From->args(), From->args_size()).value(),
+From->args_size());
+if (ToAttrOrErr)
+  ToAttr = *ToAttrOrErr;
+else
+  return ToAttrOrErr.takeError();
+break;
+  }
+  case attr::AssertExclusiveLock: {
+const auto *From = cast(FromAttr);
+AttrImporter AI(*this);
+Expected ToAttrOrErr = AI.createImportedAttr(
+From, AI.importArrayArg(From->args(), From->args_size()).value(),
+From->args_size());
+if (ToAttrOrErr)
+  ToAttr = *ToAttrOrErr;
+else
+  return ToAttrOrErr.takeError();
+break;
+  }
+  case attr::AssertSharedLock: {
+const auto *From = cast(FromAttr);
+AttrImporter AI(*this);
+Expected ToAttrOrErr = AI.createImportedAttr(
+From, AI.importArrayArg(From->args(), From->args_size()).value(),
+From->args_size());
+if (ToAttrOrErr)
+  ToAttr = *ToAttrOrErr;
+else
+  return ToAttrOrErr.takeError();
+break;
+  }
+  case attr::ExclusiveTrylockFunction: {
+const auto *From = cast(FromAttr);
+AttrImporter AI(*this);
+Expected ToAttrOrErr = AI.create

[PATCH] D110528: [clang][ASTImporter] Add import of thread safety attributes.

2021-10-05 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 rGbcefea80a40e: [clang][ASTImporter] Add import of thread 
safety attributes. (authored by balazske).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110528

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

Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -6564,6 +6564,31 @@
   EXPECT_EQ(FromAttr->getType()->getName(), ToAttr->getType()->getName());
 }
 
+TEST_P(ImportAttributes, ImportGuardedVar) {
+  GuardedVarAttr *FromAttr, *ToAttr;
+  importAttr("int test __attribute__((guarded_var));", FromAttr,
+  ToAttr);
+}
+
+TEST_P(ImportAttributes, ImportPtGuardedVar) {
+  PtGuardedVarAttr *FromAttr, *ToAttr;
+  importAttr("int *test __attribute__((pt_guarded_var));", FromAttr,
+  ToAttr);
+}
+
+TEST_P(ImportAttributes, ImportScopedLockable) {
+  ScopedLockableAttr *FromAttr, *ToAttr;
+  importAttr("struct __attribute__((scoped_lockable)) test {};",
+FromAttr, ToAttr);
+}
+
+TEST_P(ImportAttributes, ImportCapability) {
+  CapabilityAttr *FromAttr, *ToAttr;
+  importAttr(
+  "struct __attribute__((capability(\"cap\"))) test {};", FromAttr, ToAttr);
+  EXPECT_EQ(FromAttr->getName(), ToAttr->getName());
+}
+
 TEST_P(ImportAttributes, ImportAssertCapability) {
   AssertCapabilityAttr *FromAttr, *ToAttr;
   importAttr(
@@ -6572,6 +6597,147 @@
   checkImportVariadicArg(FromAttr->args(), ToAttr->args());
 }
 
+TEST_P(ImportAttributes, ImportAcquireCapability) {
+  AcquireCapabilityAttr *FromAttr, *ToAttr;
+  importAttr(
+  "void test(int A1, int A2) __attribute__((acquire_capability(A1, A2)));",
+  FromAttr, ToAttr);
+  checkImportVariadicArg(FromAttr->args(), ToAttr->args());
+}
+
+TEST_P(ImportAttributes, ImportTryAcquireCapability) {
+  TryAcquireCapabilityAttr *FromAttr, *ToAttr;
+  importAttr(
+  "void test(int A1, int A2) __attribute__((try_acquire_capability(1, A1, "
+  "A2)));",
+  FromAttr, ToAttr);
+  checkImported(FromAttr->getSuccessValue(), ToAttr->getSuccessValue());
+  checkImportVariadicArg(FromAttr->args(), ToAttr->args());
+}
+
+TEST_P(ImportAttributes, ImportReleaseCapability) {
+  ReleaseCapabilityAttr *FromAttr, *ToAttr;
+  importAttr(
+  "void test(int A1, int A2) __attribute__((release_capability(A1, A2)));",
+  FromAttr, ToAttr);
+  checkImportVariadicArg(FromAttr->args(), ToAttr->args());
+}
+
+TEST_P(ImportAttributes, ImportRequiresCapability) {
+  RequiresCapabilityAttr *FromAttr, *ToAttr;
+  importAttr(
+  "void test(int A1, int A2) __attribute__((requires_capability(A1, A2)));",
+  FromAttr, ToAttr);
+  checkImportVariadicArg(FromAttr->args(), ToAttr->args());
+}
+
+TEST_P(ImportAttributes, ImportNoThreadSafetyAnalysis) {
+  NoThreadSafetyAnalysisAttr *FromAttr, *ToAttr;
+  importAttr(
+  "void test() __attribute__((no_thread_safety_analysis));", FromAttr,
+  ToAttr);
+}
+
+TEST_P(ImportAttributes, ImportGuardedBy) {
+  GuardedByAttr *FromAttr, *ToAttr;
+  importAttr(
+  R"(
+  int G;
+  int test __attribute__((guarded_by(G)));
+  )",
+  FromAttr, ToAttr);
+  checkImported(FromAttr->getArg(), ToAttr->getArg());
+}
+
+TEST_P(ImportAttributes, ImportPtGuardedBy) {
+  PtGuardedByAttr *FromAttr, *ToAttr;
+  importAttr(
+  R"(
+  int G;
+  int *test __attribute__((pt_guarded_by(G)));
+  )",
+  FromAttr, ToAttr);
+  checkImported(FromAttr->getArg(), ToAttr->getArg());
+}
+
+TEST_P(ImportAttributes, ImportAcquiredAfter) {
+  AcquiredAfterAttr *FromAttr, *ToAttr;
+  importAttr(
+  R"(
+  struct __attribute__((lockable)) L {};
+  L A1;
+  L A2;
+  L test __attribute__((acquired_after(A1, A2)));
+  )",
+  FromAttr, ToAttr);
+  checkImportVariadicArg(FromAttr->args(), ToAttr->args());
+}
+
+TEST_P(ImportAttributes, ImportAcquiredBefore) {
+  AcquiredBeforeAttr *FromAttr, *ToAttr;
+  importAttr(
+  R"(
+  struct __attribute__((lockable)) L {};
+  L A1;
+  L A2;
+  L test __attribute__((acquired_before(A1, A2)));
+  )",
+  FromAttr, ToAttr);
+  checkImportVariadicArg(FromAttr->args(), ToAttr->args());
+}
+
+TEST_P(ImportAttributes, ImportAssertExclusiveLock) {
+  AssertExclusiveLockAttr *FromAttr, *ToAttr;
+  importAttr("void test(int A1, int A2) "
+   "__attribute__((assert_exclusive_lock(A1, A2)));",
+   FromAttr, ToAttr);
+  checkImportVariadicArg(FromAttr->args(), ToAttr->args());
+}
+
+TEST_P(ImportAttributes, ImportAssertSharedLock) {
+  AssertSharedLockAttr *FromAttr, *ToAttr;
+  importAttr(
+  "void test(int A1, int A2) _

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

2021-10-05 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added inline comments.



Comment at: clang/lib/Basic/Targets/SPIR.h:59
+// translation). This mapping is enabled when the language mode is HIP.
+1, // cuda_device
+// cuda_constant pointer can be casted to default/"flat" pointer, but in

bader wrote:
> Anastasia wrote:
> > bader wrote:
> > > Anastasia wrote:
> > > > linjamaki wrote:
> > > > > bader wrote:
> > > > > > keryell wrote:
> > > > > > > Anastasia wrote:
> > > > > > > > bader wrote:
> > > > > > > > > Anastasia wrote:
> > > > > > > > > > I am slightly confused as in the LLVM project those address 
> > > > > > > > > > spaces are for SPIR not SPIR-V though. It is however used 
> > > > > > > > > > outside of LLVM project by some tools like SPIRV-LLVM 
> > > > > > > > > > Translator as a path to SPIR-V, but it has only been done 
> > > > > > > > > > as a workaround since we had no SPIR-V support in the LLVM 
> > > > > > > > > > project yet. And if we are adding it let's do it clean to 
> > > > > > > > > > avoid/resolve any confusion.
> > > > > > > > > > 
> > > > > > > > > > I think we need to keep both because some vendors do 
> > > > > > > > > > target/use SPIR but not SPIR-V.
> > > > > > > > > > 
> > > > > > > > > > So if you are interested in SPIR-V and not SPIR you should 
> > > > > > > > > > probably add a new target that will make things cleaner.
> > > > > > > > > > I think we need to keep both because some vendors do 
> > > > > > > > > > target/use SPIR but not SPIR-V.
> > > > > > > > > 
> > > > > > > > > @Anastasia, could you elaborate more on the difference 
> > > > > > > > > between SPIR and SPIR-V?
> > > > > > > > > I would like to understand what these terms mean in the 
> > > > > > > > > context of LLVM project.
> > > > > > > > Their conceptual differences are just that they are two 
> > > > > > > > different intermediate formats.
> > > > > > > > 
> > > > > > > > The important thing to highlight is that it is not impossible 
> > > > > > > > that some vendors use SPIR (without using SPIR-V) even despite 
> > > > > > > > the fact it has been discontinued by Khronos. 
> > > > > > > > 
> > > > > > > > Nobody has deprecated or discontinued SPIR in the LLVM project 
> > > > > > > > yet.
> > > > > > > > Their conceptual differences are just that they are two 
> > > > > > > > different intermediate formats.
> > > > > > > > 
> > > > > > > > The important thing to highlight is that it is not impossible 
> > > > > > > > that some vendors use SPIR (without using SPIR-V) even despite 
> > > > > > > > the fact it has been discontinued by Khronos. 
> > > > > > > > 
> > > > > > > > Nobody has deprecated or discontinued SPIR in the LLVM project 
> > > > > > > > yet.
> > > > > > > 
> > > > > > > All the official Xilinx OpenCL stack is based on legacy SPIR 
> > > > > > > (encoded in LLVM 6.x IR but this is another story) and I suspect 
> > > > > > > this is the case for other companies.
> > > > > > > So, do not deprecate or discontinue, please. :-)
> > > > > > > The important thing to highlight is that it is not impossible 
> > > > > > > that some vendors use SPIR (without using SPIR-V) even despite 
> > > > > > > the fact it has been discontinued by Khronos.
> > > > > > > Nobody has deprecated or discontinued SPIR in the LLVM project 
> > > > > > > yet.
> > > > > > 
> > > > > > Strictly speaking `SPIR` is not defined as an intermediate 
> > > > > > language. Khronos defines `SPIR-1.2` and `SPIR-2.0` formats which 
> > > > > > are based on LLVM 3.2 and LLVM 3.4 version 
> > > > > > (https://www.khronos.org/spir/). There is no definition of SPIR 
> > > > > > format based on current version of LLVM IR. Another note is that 
> > > > > > metadata and intrinsics emitted for OpenCL with clang-14 doesn't 
> > > > > > follow neither `SPIR-1.2` nor `SPIR-2.0`.
> > > > > > 
> > > > > > I always think of LLVM IR as leaving thing that is subject to 
> > > > > > change by LLVM community, so tools working with LLVM IR must adjust 
> > > > > > to the particular version (e.g. release version like LLVM 13 or 
> > > > > > ToT). We apply this logic to SPIRV-LLVM-Translator tool and update 
> > > > > > it according to LLVM format changes (e.g. kernel argument 
> > > > > > information defined in Khronos spec must be named metadata whereas 
> > > > > > clang emits function metadata).
> > > > > > 
> > > > > > > I am slightly confused as in the LLVM project those address 
> > > > > > > spaces are for SPIR not SPIR-V though.
> > > > > > [skip]
> > > > > > > Their conceptual differences are just that they are two different 
> > > > > > > intermediate formats.
> > > > > > 
> > > > > > If this is the only difference, I don't think it a good idea to 
> > > > > > create another LLVM target to separate SPIR and SPIR-V. From my 
> > > > > > point of view it creates logic ambiguity and code duplication with 
> > > > > > no additional value. @Anastasia, what problems do you see if we 
> > > > > > continue treating LLVM IR with spir* targe

[PATCH] D109144: [SPIR-V] Add SPIR-V triple architecture and clang target info

2021-10-05 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment.

In D109144#3042014 , @bader wrote:

> In D109144#3032865 , @Anastasia 
> wrote:
>
>> It would be good to get closure on this asap.
>>
>> @bader We had related discussions on the other reviews about the approach in 
>> this patch. If you have any concerns/suggestions can you please notify 
>> asap...
>
> Sorry for the delay. I was on vacation last week. I've added my concerns to 
> the discussion in https://reviews.llvm.org/D108621.



In D109144#3042014 , @bader wrote:

> In D109144#3032865 , @Anastasia 
> wrote:
>
>> It would be good to get closure on this asap.
>>
>> @bader We had related discussions on the other reviews about the approach in 
>> this patch. If you have any concerns/suggestions can you please notify 
>> asap...
>
> Sorry for the delay. I was on vacation last week. I've added my concerns to 
> the discussion in https://reviews.llvm.org/D108621.

Thanks! Just to summarize here current discussions, the following approaches 
for the SPIR-V support in Clang are being discussed:

1. Implementing SPIR-V target as SPIR target.  @bader do you suggest that we 
add `spirv` triple to clang and map it into SPIR taget or do you suggest 
something different? We provide documentation and wider communication in the 
community that SPIR and SPIR-V are the same target and will be evolved the same 
way. This would mean that if we do require modifications that are not backward 
compatible the old ABI might be broken and tools using SPIR would have to 
adapt. Or if we are to avoid such modifications we would not be able to make a 
significant improvement to SPIR-V if there are any.
2. Create SPIR-V target as a subclass of SPIR deriving most of the common 
functionality but leaving the ability to deviate freely. This is essentially 
what this patch implements. The concern is the code duplication although that 
should be minimal considering that C++ inheritance and metaprogramming features 
can be used to effectively share the code.

I think to unblock this thread we should request further feedback from the 
community.

- What architectural changes are needed/desired for SPIR-V tooling in LLVM and 
whether they can be done uniformaly for SPIR and SPIR-V.
- What is the envisioned tooling evolution for SPIR and SPIR-V and could we 
safely consider that they are aligned?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109144

___
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-10-05 Thread Alexey Bader via Phabricator via cfe-commits
bader added inline comments.



Comment at: clang/lib/Basic/Targets/SPIR.h:59
+// translation). This mapping is enabled when the language mode is HIP.
+1, // cuda_device
+// cuda_constant pointer can be casted to default/"flat" pointer, but in

Anastasia wrote:
> bader wrote:
> > Anastasia wrote:
> > > bader wrote:
> > > > Anastasia wrote:
> > > > > linjamaki wrote:
> > > > > > bader wrote:
> > > > > > > keryell wrote:
> > > > > > > > Anastasia wrote:
> > > > > > > > > bader wrote:
> > > > > > > > > > Anastasia wrote:
> > > > > > > > > > > I am slightly confused as in the LLVM project those 
> > > > > > > > > > > address spaces are for SPIR not SPIR-V though. It is 
> > > > > > > > > > > however used outside of LLVM project by some tools like 
> > > > > > > > > > > SPIRV-LLVM Translator as a path to SPIR-V, but it has 
> > > > > > > > > > > only been done as a workaround since we had no SPIR-V 
> > > > > > > > > > > support in the LLVM project yet. And if we are adding it 
> > > > > > > > > > > let's do it clean to avoid/resolve any confusion.
> > > > > > > > > > > 
> > > > > > > > > > > I think we need to keep both because some vendors do 
> > > > > > > > > > > target/use SPIR but not SPIR-V.
> > > > > > > > > > > 
> > > > > > > > > > > So if you are interested in SPIR-V and not SPIR you 
> > > > > > > > > > > should probably add a new target that will make things 
> > > > > > > > > > > cleaner.
> > > > > > > > > > > I think we need to keep both because some vendors do 
> > > > > > > > > > > target/use SPIR but not SPIR-V.
> > > > > > > > > > 
> > > > > > > > > > @Anastasia, could you elaborate more on the difference 
> > > > > > > > > > between SPIR and SPIR-V?
> > > > > > > > > > I would like to understand what these terms mean in the 
> > > > > > > > > > context of LLVM project.
> > > > > > > > > Their conceptual differences are just that they are two 
> > > > > > > > > different intermediate formats.
> > > > > > > > > 
> > > > > > > > > The important thing to highlight is that it is not impossible 
> > > > > > > > > that some vendors use SPIR (without using SPIR-V) even 
> > > > > > > > > despite the fact it has been discontinued by Khronos. 
> > > > > > > > > 
> > > > > > > > > Nobody has deprecated or discontinued SPIR in the LLVM 
> > > > > > > > > project yet.
> > > > > > > > > Their conceptual differences are just that they are two 
> > > > > > > > > different intermediate formats.
> > > > > > > > > 
> > > > > > > > > The important thing to highlight is that it is not impossible 
> > > > > > > > > that some vendors use SPIR (without using SPIR-V) even 
> > > > > > > > > despite the fact it has been discontinued by Khronos. 
> > > > > > > > > 
> > > > > > > > > Nobody has deprecated or discontinued SPIR in the LLVM 
> > > > > > > > > project yet.
> > > > > > > > 
> > > > > > > > All the official Xilinx OpenCL stack is based on legacy SPIR 
> > > > > > > > (encoded in LLVM 6.x IR but this is another story) and I 
> > > > > > > > suspect this is the case for other companies.
> > > > > > > > So, do not deprecate or discontinue, please. :-)
> > > > > > > > The important thing to highlight is that it is not impossible 
> > > > > > > > that some vendors use SPIR (without using SPIR-V) even despite 
> > > > > > > > the fact it has been discontinued by Khronos.
> > > > > > > > Nobody has deprecated or discontinued SPIR in the LLVM project 
> > > > > > > > yet.
> > > > > > > 
> > > > > > > Strictly speaking `SPIR` is not defined as an intermediate 
> > > > > > > language. Khronos defines `SPIR-1.2` and `SPIR-2.0` formats which 
> > > > > > > are based on LLVM 3.2 and LLVM 3.4 version 
> > > > > > > (https://www.khronos.org/spir/). There is no definition of SPIR 
> > > > > > > format based on current version of LLVM IR. Another note is that 
> > > > > > > metadata and intrinsics emitted for OpenCL with clang-14 doesn't 
> > > > > > > follow neither `SPIR-1.2` nor `SPIR-2.0`.
> > > > > > > 
> > > > > > > I always think of LLVM IR as leaving thing that is subject to 
> > > > > > > change by LLVM community, so tools working with LLVM IR must 
> > > > > > > adjust to the particular version (e.g. release version like LLVM 
> > > > > > > 13 or ToT). We apply this logic to SPIRV-LLVM-Translator tool and 
> > > > > > > update it according to LLVM format changes (e.g. kernel argument 
> > > > > > > information defined in Khronos spec must be named metadata 
> > > > > > > whereas clang emits function metadata).
> > > > > > > 
> > > > > > > > I am slightly confused as in the LLVM project those address 
> > > > > > > > spaces are for SPIR not SPIR-V though.
> > > > > > > [skip]
> > > > > > > > Their conceptual differences are just that they are two 
> > > > > > > > different intermediate formats.
> > > > > > > 
> > > > > > > If this is the only difference, I don't think it a good idea to 
> > > > > > > create another LLVM target to separate SPIR and SPIR-V. From my 
> > > > >

[clang] 424733c - Implement if consteval (P1938)

2021-10-05 Thread Aaron Ballman via cfe-commits

Author: Corentin Jabot
Date: 2021-10-05T08:04:14-04:00
New Revision: 424733c12aacc227a28114deba72061153f8dff2

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

LOG: Implement if consteval (P1938)

Modify the IfStmt node to suppoort constant evaluated expressions.

Add a new ExpressionEvaluationContext::ImmediateFunctionContext to
keep track of immediate function contexts.

This proved easier/better/probably more efficient than walking the AST
backward as it allows diagnosing nested if consteval statements.

Added: 
clang/test/AST/Interp/if_consteval.cpp
clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p4.cpp
clang/test/CodeGenCXX/cxx2b-consteval-if.cpp

Modified: 
clang/include/clang/AST/Stmt.h
clang/include/clang/Basic/DiagnosticParseKinds.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Basic/Specifiers.h
clang/include/clang/Sema/Sema.h
clang/lib/AST/ASTImporter.cpp
clang/lib/AST/ExprConstant.cpp
clang/lib/AST/Interp/ByteCodeStmtGen.cpp
clang/lib/AST/JSONNodeDumper.cpp
clang/lib/AST/Stmt.cpp
clang/lib/AST/StmtPrinter.cpp
clang/lib/AST/TextNodeDumper.cpp
clang/lib/Analysis/BodyFarm.cpp
clang/lib/Analysis/CFG.cpp
clang/lib/CodeGen/CGStmt.cpp
clang/lib/CodeGen/CodeGenPGO.cpp
clang/lib/Frontend/InitPreprocessor.cpp
clang/lib/Parse/ParseStmt.cpp
clang/lib/Sema/JumpDiagnostics.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaExprMember.cpp
clang/lib/Sema/SemaLambda.cpp
clang/lib/Sema/SemaStmt.cpp
clang/lib/Sema/TreeTransform.h
clang/lib/Serialization/ASTReaderStmt.cpp
clang/lib/Serialization/ASTWriterStmt.cpp
clang/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp
clang/test/AST/ast-dump-if-json.cpp
clang/test/AST/ast-dump-stmt.cpp

Removed: 




diff  --git a/clang/include/clang/AST/Stmt.h b/clang/include/clang/AST/Stmt.h
index 8e1d7df970963..73cbff537847d 100644
--- a/clang/include/clang/AST/Stmt.h
+++ b/clang/include/clang/AST/Stmt.h
@@ -20,6 +20,7 @@
 #include "clang/Basic/IdentifierTable.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/Specifiers.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/BitmaskEnum.h"
 #include "llvm/ADT/PointerIntPair.h"
@@ -160,8 +161,8 @@ class alignas(void *) Stmt {
 
 unsigned : NumStmtBits;
 
-/// True if this if statement is a constexpr if.
-unsigned IsConstexpr : 1;
+/// Whether this is a constexpr if, or a consteval if, or neither.
+unsigned Kind : 3;
 
 /// True if this if statement has storage for an else statement.
 unsigned HasElse : 1;
@@ -1950,8 +1951,8 @@ class IfStmt final
   unsigned elseOffset() const { return condOffset() + ElseOffsetFromCond; }
 
   /// Build an if/then/else statement.
-  IfStmt(const ASTContext &Ctx, SourceLocation IL, bool IsConstexpr, Stmt 
*Init,
- VarDecl *Var, Expr *Cond, SourceLocation LParenLoc,
+  IfStmt(const ASTContext &Ctx, SourceLocation IL, IfStatementKind Kind,
+ Stmt *Init, VarDecl *Var, Expr *Cond, SourceLocation LParenLoc,
  SourceLocation RParenLoc, Stmt *Then, SourceLocation EL, Stmt *Else);
 
   /// Build an empty if/then/else statement.
@@ -1960,9 +1961,9 @@ class IfStmt final
 public:
   /// Create an IfStmt.
   static IfStmt *Create(const ASTContext &Ctx, SourceLocation IL,
-bool IsConstexpr, Stmt *Init, VarDecl *Var, Expr *Cond,
-SourceLocation LPL, SourceLocation RPL, Stmt *Then,
-SourceLocation EL = SourceLocation(),
+IfStatementKind Kind, Stmt *Init, VarDecl *Var,
+Expr *Cond, SourceLocation LPL, SourceLocation RPL,
+Stmt *Then, SourceLocation EL = SourceLocation(),
 Stmt *Else = nullptr);
 
   /// Create an empty IfStmt optionally with storage for an else statement,
@@ -2077,8 +2078,30 @@ class IfStmt final
 *getTrailingObjects() = ElseLoc;
   }
 
-  bool isConstexpr() const { return IfStmtBits.IsConstexpr; }
-  void setConstexpr(bool C) { IfStmtBits.IsConstexpr = C; }
+  bool isConsteval() const {
+return getStatementKind() == IfStatementKind::ConstevalNonNegated ||
+   getStatementKind() == IfStatementKind::ConstevalNegated;
+  }
+
+  bool isNonNegatedConsteval() const {
+return getStatementKind() == IfStatementKind::ConstevalNonNegated;
+  }
+
+  bool isNegatedConsteval() const {
+return getStatementKind() == IfStatementKind::ConstevalNegated;
+  }
+
+  bool isConstexpr() const {
+return getStatementKind() == IfStatementKind::Constexpr;
+  }
+
+  void setStatementKind(IfStatementKind Kind) {
+IfStmtBits.Kind

[PATCH] D111134: Add basic aarch64-none-elf bare metal driver.

2021-10-05 Thread Kristof Beyls via Phabricator via cfe-commits
kristof.beyls created this revision.
kristof.beyls added reviewers: psmith, miyuki, srhines.
Herald added subscribers: s.egerton, simoncook.
kristof.beyls 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/D34

Files:
  clang/lib/Driver/ToolChains/BareMetal.cpp
  clang/test/Driver/baremetal.cpp
  clang/test/Driver/gcc_forward.c


Index: clang/test/Driver/gcc_forward.c
===
--- clang/test/Driver/gcc_forward.c
+++ clang/test/Driver/gcc_forward.c
@@ -1,4 +1,4 @@
-// RUN: %clang -### %s -target aarch64-none-elf \
+// RUN: %clang -### %s -target x86-none-elf \
 // RUN:   --coverage -e _start -fuse-ld=lld --ld-path=ld -nostartfiles \
 // RUN:   -nostdlib -r -rdynamic -specs=nosys.specs -static -static-pie \
 // RUN:   2>&1 | FileCheck --check-prefix=FORWARD %s
Index: clang/test/Driver/baremetal.cpp
===
--- clang/test/Driver/baremetal.cpp
+++ clang/test/Driver/baremetal.cpp
@@ -102,6 +102,21 @@
 // RUN:   | FileCheck %s --check-prefix=CHECK-SYSROOT-INC
 // CHECK-SYSROOT-INC-NOT: "-internal-isystem" "include"
 
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN:  -target aarch64-none-elf \
+// RUN:   | FileCheck --check-prefix=CHECK-AARCH64-NO-HOST-INC %s
+// Verify that the bare metal driver does not include any host system paths.
+// I.e. verify it only includes paths relative to the clang binary, when no
+// sysroot is specified.
+// We are constrained a little bit by FileCheck's features here, so just
+// check that the first -internal-isystem points to an include path in the
+// clang install, not somewhere else. Ideally, we'd verify this for all
+// -internal-isystem paths, but we don't know how many to expect, so that is
+// hard to test for exactly here.
+// CHECK-AARCH64-NO-HOST-INC: InstalledDir: [[INSTALLEDDIR:.+]]
+// CHECK-AARCH64-NO-HOST-INC: "-internal-isystem" "[[INSTALLEDDIR]]
+
+
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN: -target riscv64-unknown-elf \
 // RUN: -L some/directory/user/asked/for \
Index: clang/lib/Driver/ToolChains/BareMetal.cpp
===
--- clang/lib/Driver/ToolChains/BareMetal.cpp
+++ clang/lib/Driver/ToolChains/BareMetal.cpp
@@ -125,6 +125,21 @@
   return true;
 }
 
+/// Is the triple aarch64-none-elf?
+static bool isAArch64BareMetal(const llvm::Triple &Triple) {
+  if (Triple.getArch() != llvm::Triple::aarch64)
+return false;
+
+  if (Triple.getVendor() != llvm::Triple::UnknownVendor)
+return false;
+
+  if (Triple.getOS() != llvm::Triple::UnknownOS)
+return false;
+
+  return Triple.getEnvironmentName() == "elf";
+}
+
+
 static bool isRISCVBareMetal(const llvm::Triple &Triple) {
   if (Triple.getArch() != llvm::Triple::riscv32 &&
   Triple.getArch() != llvm::Triple::riscv64)
@@ -151,7 +166,8 @@
 }
 
 bool BareMetal::handlesTarget(const llvm::Triple &Triple) {
-  return isARMBareMetal(Triple) || isRISCVBareMetal(Triple);
+  return isARMBareMetal(Triple) || isAArch64BareMetal(Triple) ||
+isRISCVBareMetal(Triple);
 }
 
 Tool *BareMetal::buildLinker() const {


Index: clang/test/Driver/gcc_forward.c
===
--- clang/test/Driver/gcc_forward.c
+++ clang/test/Driver/gcc_forward.c
@@ -1,4 +1,4 @@
-// RUN: %clang -### %s -target aarch64-none-elf \
+// RUN: %clang -### %s -target x86-none-elf \
 // RUN:   --coverage -e _start -fuse-ld=lld --ld-path=ld -nostartfiles \
 // RUN:   -nostdlib -r -rdynamic -specs=nosys.specs -static -static-pie \
 // RUN:   2>&1 | FileCheck --check-prefix=FORWARD %s
Index: clang/test/Driver/baremetal.cpp
===
--- clang/test/Driver/baremetal.cpp
+++ clang/test/Driver/baremetal.cpp
@@ -102,6 +102,21 @@
 // RUN:   | FileCheck %s --check-prefix=CHECK-SYSROOT-INC
 // CHECK-SYSROOT-INC-NOT: "-internal-isystem" "include"
 
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN:  -target aarch64-none-elf \
+// RUN:   | FileCheck --check-prefix=CHECK-AARCH64-NO-HOST-INC %s
+// Verify that the bare metal driver does not include any host system paths.
+// I.e. verify it only includes paths relative to the clang binary, when no
+// sysroot is specified.
+// We are constrained a little bit by FileCheck's features here, so just
+// check that the first -internal-isystem points to an include path in the
+// clang install, not somewhere else. Ideally, we'd verify this for all
+// -internal-isystem paths, but we don't know how many to expect, so that is
+// hard to test for exactly here.
+// CHECK-AARCH64-NO-HOST-INC: InstalledDir: [[INSTALLEDDIR:.+]]
+// CHECK-AARCH64-NO-HOST-INC: "-internal-isystem" "[[INSTALLEDDIR]]
+
+
 // RUN: %clang -no-canonica

[PATCH] D110482: [clang] Implement if consteval (P1938)

2021-10-05 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman closed this revision.
aaron.ballman added a comment.

I've commit on your behalf in 424733c12aacc227a28114deba72061153f8dff2 
, thank 
you for the new functionality!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110482

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


[PATCH] D108194: [clangd] IncludeCleaner: Mark used headers

2021-10-05 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 377158.
kbobyrev added a comment.

Refactor FileID -> IncludeStructure::HeaderID into a separate function.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108194

Files:
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/IncludeCleaner.h
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/ParsedAST.h
  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
@@ -16,6 +16,8 @@
 namespace clangd {
 namespace {
 
+using ::testing::UnorderedElementsAre;
+
 TEST(IncludeCleaner, ReferencedLocations) {
   struct TestCase {
 std::string HeaderCode;
@@ -131,6 +133,42 @@
   }
 }
 
+TEST(IncludeCleaner, GetUnusedHeaders) {
+  llvm::StringLiteral MainFile = R"cpp(
+#include "a.h"
+#include "b.h"
+#include "dir/c.h"
+#include "dir/unused.h"
+#include "unused.h"
+void foo() {
+  a();
+  b();
+  c();
+})cpp";
+  // Build expected ast with symbols coming from headers.
+  TestTU TU;
+  TU.Filename = "foo.cpp";
+  TU.AdditionalFiles["foo.h"] = "void foo();";
+  TU.AdditionalFiles["a.h"] = "void a();";
+  TU.AdditionalFiles["b.h"] = "void b();";
+  TU.AdditionalFiles["dir/c.h"] = "void c();";
+  TU.AdditionalFiles["unused.h"] = "void unused();";
+  TU.AdditionalFiles["dir/unused.h"] = "void dirUnused();";
+  TU.AdditionalFiles["not_included.h"] = "void notIncluded();";
+  TU.ExtraArgs = {"-I" + testPath("dir")};
+  TU.Code = MainFile.str();
+  ParsedAST AST = TU.build();
+  auto UnusedIncludes = AST.computeUnusedIncludes();
+  std::vector UnusedHeaders;
+  UnusedHeaders.reserve(UnusedIncludes.size());
+  for (const auto &Include : UnusedIncludes) {
+// Strip enclosing "".
+UnusedHeaders.push_back(
+Include->Written.substr(1, Include->Written.size() - 2));
+  }
+  EXPECT_THAT(UnusedHeaders, UnorderedElementsAre("unused.h", "dir/unused.h"));
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/ParsedAST.h
===
--- clang-tools-extra/clangd/ParsedAST.h
+++ clang-tools-extra/clangd/ParsedAST.h
@@ -118,6 +118,8 @@
 return Resolver.get();
   }
 
+  std::vector computeUnusedIncludes();
+
 private:
   ParsedAST(llvm::StringRef Version,
 std::shared_ptr Preamble,
Index: clang-tools-extra/clangd/ParsedAST.cpp
===
--- clang-tools-extra/clangd/ParsedAST.cpp
+++ clang-tools-extra/clangd/ParsedAST.cpp
@@ -18,6 +18,7 @@
 #include "FeatureModule.h"
 #include "Headers.h"
 #include "HeuristicResolver.h"
+#include "IncludeCleaner.h"
 #include "IncludeFixer.h"
 #include "Preamble.h"
 #include "SourceCode.h"
@@ -624,5 +625,17 @@
 return llvm::None;
   return llvm::StringRef(Preamble->Version);
 }
+
+std::vector ParsedAST::computeUnusedIncludes() {
+  const auto &SM = getSourceManager();
+
+  auto Refs = findReferencedLocations(*this);
+  auto ReferencedFiles =
+  translateToHeaderIDs(findReferencedFiles(Refs, SM), Includes, SM);
+  auto MainFileIndex = Includes.getID(SM.getFileEntryForID(SM.getMainFileID()));
+  assert(MainFileIndex && "MainFile should always have HeaderID (0)");
+  return getUnused(*MainFileIndex, Includes, ReferencedFiles, SM);
+}
+
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/IncludeCleaner.h
===
--- clang-tools-extra/clangd/IncludeCleaner.h
+++ clang-tools-extra/clangd/IncludeCleaner.h
@@ -25,6 +25,7 @@
 #include "ParsedAST.h"
 #include "clang/Basic/SourceLocation.h"
 #include "llvm/ADT/DenseSet.h"
+#include 
 
 namespace clang {
 namespace clangd {
@@ -46,6 +47,25 @@
 /// - err on the side of reporting all possible locations
 ReferencedLocations findReferencedLocations(ParsedAST &AST);
 
+/// Retrieves IDs of all files containing SourceLocations from \p Locs.
+llvm::DenseSet findReferencedFiles(const ReferencedLocations &Locs,
+   const SourceManager &SM);
+
+/// Maps FileIDs to the internal IncludeStructure representation (HeaderIDs).
+/// \p Includes may be modified in the process while creating the HeaderIDs for
+/// previously unseen files.
+llvm::DenseSet
+translateToHeaderIDs(const llvm::DenseSet &Files,
+ IncludeStructure &Includes, const SourceManager &SM);
+
+/// Retrieves headers that are referenced from the main file (\p EntryPoint)
+/// but not used.
+std::vector
+getUnused(IncludeStructure::HeaderID EntryPoint,
+  const IncludeStructure &Includes,
+  const llvm::DenseSet &Re

[PATCH] D110670: [Sema] Allow comparisons between different ms ptr size address space types.

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

LGTM, thank you!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110670

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


[clang] aa4f4d1 - consteval if is now fully supported

2021-10-05 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2021-10-05T08:21:29-04:00
New Revision: aa4f4d18e85d65f796ee9a9549ead1c0cd56ac1d

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

LOG: consteval if is now fully supported

This amends 424733c12aacc227a28114deba72061153f8dff2 which accidentally
dropped the change to the status page.

Added: 


Modified: 
clang/www/cxx_status.html

Removed: 




diff  --git a/clang/www/cxx_status.html b/clang/www/cxx_status.html
index f3d1edf08cb97..c09b62e4ffac8 100755
--- a/clang/www/cxx_status.html
+++ b/clang/www/cxx_status.html
@@ -1289,7 +1289,7 @@ C++2b implementation status
 
   if consteval
   https://wg21.link/P1938R3";>P1938R3
-  No
+  Clang 14
 
 
   Allow duplicate attributes



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


[PATCH] D109707: [HIP] [AlwaysInliner] Disable AlwaysInliner to eliminate undefined symbols

2021-10-05 Thread Anshil Gandhi via Phabricator via cfe-commits
gandhi21299 added a comment.

ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109707

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


[PATCH] D111115: [OPENMP] Fix assert of "Unable to find base lambda address" from adjustMemberOfForLambdaCaptures.

2021-10-05 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/lib/CodeGen/CGOpenMPRuntime.cpp:8445-8463
+const ValueDecl *VD = Cap.getCapturedVar()->getCanonicalDecl();
+const auto *RD = VD->getType()
+ .getCanonicalType()
+ .getNonReferenceType()
+ ->getAsCXXRecordDecl();
+const auto *CurExecDir = CurDir.get();
+for (const auto *C : CurExecDir->getClausesOfKind())

Maybe add a new data container for mapped lambdas, similar to 
`FirstPrivateDecls` to avoid all those extra checks here?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D15

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


[PATCH] D108822: [python bindings] Add missing cursor kind in Clang Python's bindings.

2021-10-05 Thread Colin Chargy via Phabricator via cfe-commits
ColinChargy added a comment.

Hi @teerytko,
It's my first PR, so I don't know how to get this PR reviewed. I sent an e-mail 
to @rsmith without luck. Should I send another e-mail to the mailing list IYHO ?
Regards,
Colin Chargy


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108822

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


[PATCH] D108194: [clangd] IncludeCleaner: Mark used headers

2021-10-05 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:159
+std::vector
+getUnused(IncludeStructure::HeaderID EntryPoint,
+  const IncludeStructure &Structure,

EntryPoint is unused



Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:166
+// FIXME: Skip includes that are not self-contained.
+auto Entry = SM.getFileManager().getFile(MFI.Resolved);
+if (!Entry) {

Handle unresolved case somehow? (Or assert if you're sure it can't happen - I 
think it can for e.g. pp_file_not_found)



Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:166
+// FIXME: Skip includes that are not self-contained.
+auto Entry = SM.getFileManager().getFile(MFI.Resolved);
+if (!Entry) {

sammccall wrote:
> Handle unresolved case somehow? (Or assert if you're sure it can't happen - I 
> think it can for e.g. pp_file_not_found)
doesn't seem like there's any need to go through filenames for this.
Can't we just store the HeaderID in the Inclusion?
(Blech, as an `unsigned` to avoid a circular dependency)



Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:168
+if (!Entry) {
+  elog("Missing FileEntry for {0}", MFI.Resolved);
+  continue;

elog says that:
a) this might happen
b) logging for the user is the best thing we can do

Can this actually happen? My suspicion is no. In which case maybe it should be 
an assert?



Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:173
+if (!It) {
+  elog("Missing IncludeStructure::File for {0}", MFI.Resolved);
+  continue;

I'm fairly (more) certain this one should be an assert



Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:193
+if (!FE) {
+  elog("Missing FE for {0}", SM.getComposedLoc(FID, 0).printToString(SM));
+  continue;

assert?



Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:196
+}
+const auto File = Includes.getID(FE);
+if (!File) {

this is get, not getOrCreate, so you don't need the mutable reference



Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:198
+if (!File) {
+  elog("Missing FE for {0}", SM.getComposedLoc(FID, 0).printToString(SM));
+  continue;

I'm not totally sure whether this is safe to assert or not. WDYT?

In any case, please fix the message (FE -> HeaderID, add more context)



Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:158
+
+std::vector
+getUnused(IncludeStructure::HeaderID EntryPoint,

sammccall wrote:
> Why are we passing around Inclusions by value?
Sorry, should have thought this through more before leaving the comment. There 
are a couple of questions really:

How should we *store* the information about which inclusions are unused?
 - not at all, generate ReferencedFiles and compute "is this header unused" on 
the fly when generating diagnostics
 - store ReferencedFiles but call "is this header unused" on the fly
 - store a boolean or something in each Inclusion
 - store a list of the inclusions that are unused
IMO this is mostly a question of what's the lifecycle of the info, and what's 
the simplest representation - seems like we should prefer stuff higher on the 
list if we have a choice.

What should the signature of the function be?
There doesn't seem to be any work saved here by processing all the includes as 
a batch - why not simplify by just making this `bool isUnused(...)` and let the 
caller/test choose what data structures to use?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108194

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


[PATCH] D111119: [Clang][OpenMP] Infix OMPLoopTransformationDirective abstract class. NFC.

2021-10-05 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev accepted this revision.
ABataev 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/D19/new/

https://reviews.llvm.org/D19

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


[PATCH] D107141: [Inline-asm] Add structure type handling when they are tied in input and output constraints

2021-10-05 Thread Pengfei Wang via Phabricator via cfe-commits
pengfei updated this revision to Diff 377168.
pengfei added a comment.

Rebase.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107141

Files:
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/Sema/SemaStmtAsm.cpp
  clang/test/Sema/asm.c

Index: clang/test/Sema/asm.c
===
--- clang/test/Sema/asm.c
+++ clang/test/Sema/asm.c
@@ -313,3 +313,51 @@
   asm ("jne %l0":::);
   asm goto ("jne %l0"lab);
 }
+
+typedef struct test19_a {
+  int a;
+  char b;
+} test19_a;
+
+typedef struct test19_b {
+  int a;
+  int b;
+  int c;
+} test19_b;
+
+typedef struct test19_c {
+  char a;
+  char b;
+} test19_c;
+
+typedef struct test19_d {
+  char a;
+  char b;
+  char c;
+  char d;
+} test19_d;
+
+typedef struct test19_e {
+  int a;
+  int b;
+  int c;
+  int d;
+} test19_e;
+
+void test19(long long x)
+{
+  test19_a a;
+  test19_b b;
+  test19_c c;
+  test19_d d;
+  test19_e e;
+  asm ("" : "=rm" (a): "0" (1)); // no-error
+  asm ("" : "=rm" (d): "0" (1)); // no-error
+  asm ("" : "=rm" (c): "0" (x)); // no-error
+  asm ("" : "=rm" (x): "0" (a)); // no-error
+  asm ("" : "=rm" (a): "0" (d)); // no-error
+  asm ("" : "=rm" (b): "0" (1)); // expected-error {{unsupported inline asm: input with type 'int' matching output with type 'test19_b' (aka 'struct test19_b')}}
+  // FIXME: The below 2 cases should be no error.
+  asm ("" : "=rm" (e): "0" (1)); // expected-error {{unsupported inline asm: input with type 'int' matching output with type 'test19_e' (aka 'struct test19_e')}}
+  asm ("" : "=rm" (x): "0" (e)); // expected-error {{unsupported inline asm: input with type 'test19_e' (aka 'struct test19_e') matching output with type 'long long'}}
+}
Index: clang/lib/Sema/SemaStmtAsm.cpp
===
--- clang/lib/Sema/SemaStmtAsm.cpp
+++ clang/lib/Sema/SemaStmtAsm.cpp
@@ -618,14 +618,33 @@
   AD_Int, AD_FP, AD_Other
 } InputDomain, OutputDomain;
 
-if (InTy->isIntegerType() || InTy->isPointerType())
+auto IsPower2Structure = [this](QualType Ty) {
+  if (!Ty->isStructureType())
+return false;
+
+  switch (Context.getTypeSize(Ty)) {
+  default:
+return false;
+  case 8:
+  case 16:
+  case 32:
+  case 64:
+  // TODO: The maximum size GCC supports is 128 bits.
+  // We may need to extract the first element in this case.
+return true;
+  }
+};
+
+if (InTy->isIntegerType() || InTy->isPointerType() ||
+IsPower2Structure(InTy))
   InputDomain = AD_Int;
 else if (InTy->isRealFloatingType())
   InputDomain = AD_FP;
 else
   InputDomain = AD_Other;
 
-if (OutTy->isIntegerType() || OutTy->isPointerType())
+if (OutTy->isIntegerType() || OutTy->isPointerType() ||
+IsPower2Structure(OutTy))
   OutputDomain = AD_Int;
 else if (OutTy->isRealFloatingType())
   OutputDomain = AD_FP;
@@ -667,7 +686,8 @@
 // output was a register, just extend the shorter one to the size of the
 // larger one.
 if (!SmallerValueMentioned && InputDomain != AD_Other &&
-OutputConstraintInfos[TiedTo].allowsRegister())
+OutputConstraintInfos[TiedTo].allowsRegister() &&
+OutputDomain != AD_Other)
   continue;
 
 // Either both of the operands were mentioned or the smaller one was
Index: clang/lib/CodeGen/CGStmt.cpp
===
--- clang/lib/CodeGen/CGStmt.cpp
+++ clang/lib/CodeGen/CGStmt.cpp
@@ -2494,20 +2494,32 @@
   unsigned Output = Info.getTiedOperand();
   QualType OutputType = S.getOutputExpr(Output)->getType();
   QualType InputTy = InputExpr->getType();
+  uint64_t OutputSize = getContext().getTypeSize(OutputType);
+  uint64_t InputSize = getContext().getTypeSize(InputTy);
 
-  if (getContext().getTypeSize(OutputType) >
-  getContext().getTypeSize(InputTy)) {
+  if (OutputSize > InputSize) {
 // Use ptrtoint as appropriate so that we can do our extension.
 if (isa(Arg->getType()))
   Arg = Builder.CreatePtrToInt(Arg, IntPtrTy);
+if (isa(Arg->getType())) {
+  llvm::IntegerType *IntTy =
+  llvm::IntegerType::get(getLLVMContext(), InputSize);
+  Arg = Builder.CreateBitCast(Arg, IntTy);
+}
 llvm::Type *OutputTy = ConvertType(OutputType);
 if (isa(OutputTy))
   Arg = Builder.CreateZExt(Arg, OutputTy);
 else if (isa(OutputTy))
   Arg = Builder.CreateZExt(Arg, IntPtrTy);
-else {
-  assert(OutputTy->isFloatingPointTy() && "Unexpected output type");
+else if (OutputTy->isFloatingPointTy())
   Arg = Builder.CreateFPExt(Arg, OutputTy);
+else {
+  assert(OutputTy->isStructTy() && OutputSize != 128 &&
+ "Unexpected output type");
+   

[PATCH] D111124: [Clang][OpenMP] Allow loop-transformations with template parameters.

2021-10-05 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev accepted this revision.
ABataev 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/D24/new/

https://reviews.llvm.org/D24

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


[clang] 8737c74 - [PowerPC][MMA] Allow MMA builtin types in pre-P10 compilation units

2021-10-05 Thread Kamau Bridgeman via cfe-commits

Author: Kamau Bridgeman
Date: 2021-10-05T07:59:32-05:00
New Revision: 8737c74fab3aee833d85b7d235d2c47ebb4eed2e

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

LOG: [PowerPC][MMA] Allow MMA builtin types in pre-P10 compilation units

This patch allows the use of __vector_quad and __vector_pair, PPC MMA builtin
types, on all PowerPC 64-bit compilation units. When these types are
made available the builtins that use them automatically become available
so semantic checking for mma and pair vector memop __builtins is also
expanded to ensure these builtin function call are only allowed on
Power10 and new architectures. All related test cases are updated to
ensure test coverage.

Reviewed By: #powerpc, nemanjai

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

Added: 
clang/test/Sema/ppc-mma-builtins.c
clang/test/Sema/ppc-paired-vector-builtins.c

Modified: 
clang/include/clang/Sema/Sema.h
clang/lib/AST/ASTContext.cpp
clang/lib/Sema/Sema.cpp
clang/lib/Sema/SemaChecking.cpp
clang/test/AST/ast-dump-ppc-types.c
clang/test/CodeGen/ppc-mma-types.c
clang/test/CodeGenCXX/ppc-mangle-mma-types.cpp
llvm/test/CodeGen/PowerPC/mma-acc-memops.ll

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index a85e53a9a69e8..0a68f6f71b8e7 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -12705,7 +12705,8 @@ class Sema final {
 int ArgNum, unsigned ExpectedFieldNum,
 bool AllowName);
   bool SemaBuiltinARMMemoryTaggingCall(unsigned BuiltinID, CallExpr *TheCall);
-  bool SemaBuiltinPPCMMACall(CallExpr *TheCall, const char *TypeDesc);
+  bool SemaBuiltinPPCMMACall(CallExpr *TheCall, unsigned BuiltinID,
+ const char *TypeDesc);
 
   bool CheckPPCMMAType(QualType Type, SourceLocation TypeLoc);
 

diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index e2ebe737fdfdc..d1fd3ce061415 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -1444,13 +1444,10 @@ void ASTContext::InitBuiltinTypes(const TargetInfo 
&Target,
 #include "clang/Basic/AArch64SVEACLETypes.def"
   }
 
-  if (Target.getTriple().isPPC64() &&
-  Target.hasFeature("paired-vector-memops")) {
-if (Target.hasFeature("mma")) {
+  if (Target.getTriple().isPPC64()) {
 #define PPC_VECTOR_MMA_TYPE(Name, Id, Size) \
   InitBuiltinType(Id##Ty, BuiltinType::Id);
 #include "clang/Basic/PPCTypes.def"
-}
 #define PPC_VECTOR_VSX_TYPE(Name, Id, Size) \
 InitBuiltinType(Id##Ty, BuiltinType::Id);
 #include "clang/Basic/PPCTypes.def"

diff  --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index d260a45867e06..cf8dcbb6fc3ef 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -403,13 +403,10 @@ void Sema::Initialize() {
 #include "clang/Basic/AArch64SVEACLETypes.def"
   }
 
-  if (Context.getTargetInfo().getTriple().isPPC64() &&
-  Context.getTargetInfo().hasFeature("paired-vector-memops")) {
-if (Context.getTargetInfo().hasFeature("mma")) {
+  if (Context.getTargetInfo().getTriple().isPPC64()) {
 #define PPC_VECTOR_MMA_TYPE(Name, Id, Size) \
   addImplicitTypedef(#Name, Context.Id##Ty);
 #include "clang/Basic/PPCTypes.def"
-}
 #define PPC_VECTOR_VSX_TYPE(Name, Id, Size) \
 addImplicitTypedef(#Name, Context.Id##Ty);
 #include "clang/Basic/PPCTypes.def"

diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index a6d26ac65465d..0ee05c9f09a52 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -3521,9 +3521,9 @@ bool Sema::CheckPPCBuiltinFunctionCall(const TargetInfo 
&TI, unsigned BuiltinID,
   case PPC::BI__builtin_ppc_store8r:
 return SemaFeatureCheck(*this, TheCall, "isa-v206-instructions",
 diag::err_ppc_builtin_only_on_arch, "7");
-#define CUSTOM_BUILTIN(Name, Intr, Types, Acc) \
-  case PPC::BI__builtin_##Name: \
-return SemaBuiltinPPCMMACall(TheCall, Types);
+#define CUSTOM_BUILTIN(Name, Intr, Types, Acc) 
\
+  case PPC::BI__builtin_##Name:
\
+return SemaBuiltinPPCMMACall(TheCall, BuiltinID, Types);
 #include "clang/Basic/BuiltinsPPC.def"
   }
   return SemaBuiltinConstantArgRange(TheCall, i, l, u);
@@ -7481,11 +7481,35 @@ bool Sema::SemaBuiltinARMSpecialReg(unsigned BuiltinID, 
CallExpr *TheCall,
 /// Emit an error and return true on failure; return false on success.
 /// TypeStr is a string containing the type descriptor of the value returned by
 /// the builtin and the descriptors of the expected type of the arguments.
-bool Sema::SemaBuiltinPPCMMACall(CallExp

[PATCH] D109599: [PowerPC][MMA] Allow MMA builtin types in pre-P10 compilation units

2021-10-05 Thread Kamau Bridgeman via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG8737c74fab3a: [PowerPC][MMA] Allow MMA builtin types in 
pre-P10 compilation units (authored by kamaub).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D109599?vs=376300&id=377172#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109599

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/AST/ast-dump-ppc-types.c
  clang/test/CodeGen/ppc-mma-types.c
  clang/test/CodeGenCXX/ppc-mangle-mma-types.cpp
  clang/test/Sema/ppc-mma-builtins.c
  clang/test/Sema/ppc-paired-vector-builtins.c
  llvm/test/CodeGen/PowerPC/mma-acc-memops.ll

Index: llvm/test/CodeGen/PowerPC/mma-acc-memops.ll
===
--- llvm/test/CodeGen/PowerPC/mma-acc-memops.ll
+++ llvm/test/CodeGen/PowerPC/mma-acc-memops.ll
@@ -5,6 +5,18 @@
 ; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-linux-gnu \
 ; RUN:   -mcpu=pwr10 -ppc-asm-full-reg-names \
 ; RUN:   -ppc-vsr-nums-as-vr < %s | FileCheck %s --check-prefix=BE-PAIRED
+; RUN: llc -verify-machineinstrs -mcpu=pwr9 -ppc-vsr-nums-as-vr \
+; RUN:   -ppc-asm-full-reg-names -mtriple=powerpc64le-unknown-linux-gnu < %s \
+; RUN:   | FileCheck %s --check-prefix=LE-PWR9
+; RUN: llc -verify-machineinstrs -mcpu=pwr8 -ppc-vsr-nums-as-vr \
+; RUN:   -ppc-asm-full-reg-names -mtriple=powerpc64le-unknown-linux-gnu < %s \
+; RUN:   | FileCheck %s --check-prefix=LE-PWR8
+; RUN: llc -verify-machineinstrs -mcpu=pwr9 -ppc-vsr-nums-as-vr \
+; RUN:   -ppc-asm-full-reg-names -mtriple=powerpc64-unknown-linux-gnu < %s \
+; RUN:   | FileCheck %s --check-prefix=BE-PWR9
+; RUN: llc -verify-machineinstrs -mcpu=pwr8 -ppc-vsr-nums-as-vr \
+; RUN:   -ppc-asm-full-reg-names -mtriple=powerpc64-unknown-linux-gnu < %s \
+; RUN:   | FileCheck %s --check-prefix=BE-PWR8
 
 @f = common dso_local local_unnamed_addr global <512 x i1> zeroinitializer, align 16
 @g = common dso_local local_unnamed_addr global <256 x i1> zeroinitializer, align 16
@@ -35,6 +47,78 @@
 ; BE-PAIRED-NEXT:stxv vs3, 176(r3)
 ; BE-PAIRED-NEXT:stxv vs2, 160(r3)
 ; BE-PAIRED-NEXT:blr
+;
+; LE-PWR9-LABEL: testLdSt:
+; LE-PWR9:   # %bb.0: # %entry
+; LE-PWR9-NEXT:addis r3, r2, f@toc@ha
+; LE-PWR9-NEXT:addi r3, r3, f@toc@l
+; LE-PWR9-NEXT:lxv vs1, 96(r3)
+; LE-PWR9-NEXT:lxv vs0, 64(r3)
+; LE-PWR9-NEXT:lxv vs2, 112(r3)
+; LE-PWR9-NEXT:stxv vs1, 160(r3)
+; LE-PWR9-NEXT:lxv vs1, 80(r3)
+; LE-PWR9-NEXT:stxv vs2, 176(r3)
+; LE-PWR9-NEXT:stxv vs0, 128(r3)
+; LE-PWR9-NEXT:stxv vs1, 144(r3)
+; LE-PWR9-NEXT:blr
+;
+; LE-PWR8-LABEL: testLdSt:
+; LE-PWR8:   # %bb.0: # %entry
+; LE-PWR8-NEXT:addis r3, r2, f@toc@ha
+; LE-PWR8-NEXT:li r4, 96
+; LE-PWR8-NEXT:li r5, 112
+; LE-PWR8-NEXT:addi r3, r3, f@toc@l
+; LE-PWR8-NEXT:lxvd2x vs0, r3, r4
+; LE-PWR8-NEXT:li r4, 64
+; LE-PWR8-NEXT:lxvd2x vs1, r3, r5
+; LE-PWR8-NEXT:li r5, 80
+; LE-PWR8-NEXT:lxvd2x vs2, r3, r4
+; LE-PWR8-NEXT:lxvd2x vs3, r3, r5
+; LE-PWR8-NEXT:li r4, 176
+; LE-PWR8-NEXT:li r5, 160
+; LE-PWR8-NEXT:stxvd2x vs1, r3, r4
+; LE-PWR8-NEXT:li r4, 144
+; LE-PWR8-NEXT:stxvd2x vs0, r3, r5
+; LE-PWR8-NEXT:li r5, 128
+; LE-PWR8-NEXT:stxvd2x vs3, r3, r4
+; LE-PWR8-NEXT:stxvd2x vs2, r3, r5
+; LE-PWR8-NEXT:blr
+;
+; BE-PWR9-LABEL: testLdSt:
+; BE-PWR9:   # %bb.0: # %entry
+; BE-PWR9-NEXT:addis r3, r2, f@toc@ha
+; BE-PWR9-NEXT:addi r3, r3, f@toc@l
+; BE-PWR9-NEXT:lxv vs1, 96(r3)
+; BE-PWR9-NEXT:lxv vs0, 64(r3)
+; BE-PWR9-NEXT:lxv vs2, 112(r3)
+; BE-PWR9-NEXT:stxv vs1, 160(r3)
+; BE-PWR9-NEXT:lxv vs1, 80(r3)
+; BE-PWR9-NEXT:stxv vs2, 176(r3)
+; BE-PWR9-NEXT:stxv vs0, 128(r3)
+; BE-PWR9-NEXT:stxv vs1, 144(r3)
+; BE-PWR9-NEXT:blr
+;
+; BE-PWR8-LABEL: testLdSt:
+; BE-PWR8:   # %bb.0: # %entry
+; BE-PWR8-NEXT:addis r3, r2, f@toc@ha
+; BE-PWR8-NEXT:li r4, 96
+; BE-PWR8-NEXT:li r5, 112
+; BE-PWR8-NEXT:addi r3, r3, f@toc@l
+; BE-PWR8-NEXT:lxvd2x vs0, r3, r4
+; BE-PWR8-NEXT:li r4, 64
+; BE-PWR8-NEXT:lxvd2x vs1, r3, r5
+; BE-PWR8-NEXT:li r5, 80
+; BE-PWR8-NEXT:lxvd2x vs2, r3, r4
+; BE-PWR8-NEXT:lxvd2x vs3, r3, r5
+; BE-PWR8-NEXT:li r4, 176
+; BE-PWR8-NEXT:li r5, 160
+; BE-PWR8-NEXT:stxvd2x vs1, r3, r4
+; BE-PWR8-NEXT:li r4, 144
+; BE-PWR8-NEXT:stxvd2x vs0, r3, r5
+; BE-PWR8-NEXT:li r5, 128
+; BE-PWR8-NEXT:stxvd2x vs3, r3, r4
+; BE-PWR8-NEXT:stxvd2x vs2, r3, r5
+; BE-PWR8-NEXT:blr
 entry:
   %arrayidx = getelementptr inbounds <512 x i1>, <512 x i1>* @f, i64 1
   %0 = load <512 x i1>, <512 x i1>* %arrayidx, align 64
@@ -78,6 +162,84 @@
 ; BE-PAIRED-NEXT:stxv vs3, 48(r3)
 ;

[PATCH] D109599: [PowerPC][MMA] Allow MMA builtin types in pre-P10 compilation units

2021-10-05 Thread Kamau Bridgeman via Phabricator via cfe-commits
kamaub marked an inline comment as done.
kamaub added a comment.

Updated an existing test for the backend with pwr8 and pwr9 be/le targets 
during commit


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109599

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


[clang] f4f9ad0 - Reland "[clang-repl] Allow loading of plugins in clang-repl."

2021-10-05 Thread Vassil Vassilev via cfe-commits

Author: Vassil Vassilev
Date: 2021-10-05T13:04:01Z
New Revision: f4f9ad0f5d8e8994c677c3712dff7585bf8bd963

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

LOG: Reland "[clang-repl] Allow loading of plugins in clang-repl."

Differential revision: https://reviews.llvm.org/D110484

Added: 
clang/test/Interpreter/plugins.cpp

Modified: 
clang/include/clang/Frontend/CompilerInstance.h
clang/lib/Frontend/CompilerInstance.cpp
clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
clang/lib/Interpreter/IncrementalParser.cpp
clang/tools/clang-repl/CMakeLists.txt
clang/tools/clang-repl/ClangRepl.cpp

Removed: 




diff  --git a/clang/include/clang/Frontend/CompilerInstance.h 
b/clang/include/clang/Frontend/CompilerInstance.h
index 861b15020329b..74e152ea59520 100644
--- a/clang/include/clang/Frontend/CompilerInstance.h
+++ b/clang/include/clang/Frontend/CompilerInstance.h
@@ -219,6 +219,9 @@ class CompilerInstance : public ModuleLoader {
   // of the context or else not CompilerInstance specific.
   bool ExecuteAction(FrontendAction &Act);
 
+  /// Load the list of plugins requested in the \c FrontendOptions.
+  void LoadRequestedPlugins();
+
   /// }
   /// @name Compiler Invocation and Options
   /// {

diff  --git a/clang/lib/Frontend/CompilerInstance.cpp 
b/clang/lib/Frontend/CompilerInstance.cpp
index 8de2e75388bed..a9c7566163560 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -23,6 +23,7 @@
 #include "clang/Frontend/FrontendAction.h"
 #include "clang/Frontend/FrontendActions.h"
 #include "clang/Frontend/FrontendDiagnostic.h"
+#include "clang/Frontend/FrontendPluginRegistry.h"
 #include "clang/Frontend/LogDiagnosticPrinter.h"
 #include "clang/Frontend/SerializedDiagnosticPrinter.h"
 #include "clang/Frontend/TextDiagnosticPrinter.h"
@@ -1029,6 +1030,27 @@ bool CompilerInstance::ExecuteAction(FrontendAction 
&Act) {
   return !getDiagnostics().getClient()->getNumErrors();
 }
 
+void CompilerInstance::LoadRequestedPlugins() {
+  // Load any requested plugins.
+  for (const std::string &Path : getFrontendOpts().Plugins) {
+std::string Error;
+if (llvm::sys::DynamicLibrary::LoadLibraryPermanently(Path.c_str(), 
&Error))
+  getDiagnostics().Report(diag::err_fe_unable_to_load_plugin)
+  << Path << Error;
+  }
+
+  // Check if any of the loaded plugins replaces the main AST action
+  for (const FrontendPluginRegistry::entry &Plugin :
+   FrontendPluginRegistry::entries()) {
+std::unique_ptr P(Plugin.instantiate());
+if (P->getActionType() == PluginASTAction::ReplaceAction) {
+  getFrontendOpts().ProgramAction = clang::frontend::PluginAction;
+  getFrontendOpts().ActionName = Plugin.getName().str();
+  break;
+}
+  }
+}
+
 /// Determine the appropriate source input kind based on language
 /// options.
 static Language getLanguageFromOptions(const LangOptions &LangOpts) {

diff  --git a/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp 
b/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
index b95851e380d28..dc8409f88dfad 100644
--- a/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
+++ b/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
@@ -203,24 +203,7 @@ bool ExecuteCompilerInvocation(CompilerInstance *Clang) {
 return true;
   }
 
-  // Load any requested plugins.
-  for (const std::string &Path : Clang->getFrontendOpts().Plugins) {
-std::string Error;
-if (llvm::sys::DynamicLibrary::LoadLibraryPermanently(Path.c_str(), 
&Error))
-  Clang->getDiagnostics().Report(diag::err_fe_unable_to_load_plugin)
-<< Path << Error;
-  }
-
-  // Check if any of the loaded plugins replaces the main AST action
-  for (const FrontendPluginRegistry::entry &Plugin :
-   FrontendPluginRegistry::entries()) {
-std::unique_ptr P(Plugin.instantiate());
-if (P->getActionType() == PluginASTAction::ReplaceAction) {
-  Clang->getFrontendOpts().ProgramAction = clang::frontend::PluginAction;
-  Clang->getFrontendOpts().ActionName = Plugin.getName().str();
-  break;
-}
-  }
+  Clang->LoadRequestedPlugins();
 
   // Honor -mllvm.
   //

diff  --git a/clang/lib/Interpreter/IncrementalParser.cpp 
b/clang/lib/Interpreter/IncrementalParser.cpp
index 897e2cd1aaed8..6c5a26e599033 100644
--- a/clang/lib/Interpreter/IncrementalParser.cpp
+++ b/clang/lib/Interpreter/IncrementalParser.cpp
@@ -65,6 +65,8 @@ class IncrementalAction : public WrapperFrontendAction {
   case frontend::ParseSyntaxOnly:
 Act = CreateFrontendAction(CI);
 break;
+  case frontend::PluginAction:
+LLVM_FALLTHROUGH;
   case frontend::EmitAssembly:
 LLVM_FALLTHROUGH;
   case frontend::EmitObj:

diff 

[PATCH] D108194: [clangd] IncludeCleaner: Mark used headers

2021-10-05 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:158
+
+std::vector
+getUnused(IncludeStructure::HeaderID EntryPoint,

sammccall wrote:
> sammccall wrote:
> > Why are we passing around Inclusions by value?
> Sorry, should have thought this through more before leaving the comment. 
> There are a couple of questions really:
> 
> How should we *store* the information about which inclusions are unused?
>  - not at all, generate ReferencedFiles and compute "is this header unused" 
> on the fly when generating diagnostics
>  - store ReferencedFiles but call "is this header unused" on the fly
>  - store a boolean or something in each Inclusion
>  - store a list of the inclusions that are unused
> IMO this is mostly a question of what's the lifecycle of the info, and what's 
> the simplest representation - seems like we should prefer stuff higher on the 
> list if we have a choice.
> 
> What should the signature of the function be?
> There doesn't seem to be any work saved here by processing all the includes 
> as a batch - why not simplify by just making this `bool isUnused(...)` and 
> let the caller/test choose what data structures to use?
OK I was confused, nothing is getting stored, but ParsedAST::getUnused() 
function creates/destroys the analysis data so it needs to run as a batch.

I think probably:
 - *this* function should just be a simple `bool isUnused(...)` and the loop 
lives in the caller
 - `ParsedAST::getUnused()` should become `getUnused(const ParsedAST&)` and 
live in this file

We have some circularity between ParsedAST and IncludeCleaner, but I think 
we're going to have that in any case due to `findReferencedLocations()`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108194

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


[PATCH] D108194: [clangd] IncludeCleaner: Mark used headers

2021-10-05 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 377197.
kbobyrev marked 10 inline comments as done.
kbobyrev added a comment.

Address review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108194

Files:
  clang-tools-extra/clangd/Headers.cpp
  clang-tools-extra/clangd/Headers.h
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/IncludeCleaner.h
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/ParsedAST.h
  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
@@ -16,6 +16,8 @@
 namespace clangd {
 namespace {
 
+using ::testing::UnorderedElementsAre;
+
 TEST(IncludeCleaner, ReferencedLocations) {
   struct TestCase {
 std::string HeaderCode;
@@ -131,6 +133,42 @@
   }
 }
 
+TEST(IncludeCleaner, GetUnusedHeaders) {
+  llvm::StringLiteral MainFile = R"cpp(
+#include "a.h"
+#include "b.h"
+#include "dir/c.h"
+#include "dir/unused.h"
+#include "unused.h"
+void foo() {
+  a();
+  b();
+  c();
+})cpp";
+  // Build expected ast with symbols coming from headers.
+  TestTU TU;
+  TU.Filename = "foo.cpp";
+  TU.AdditionalFiles["foo.h"] = "void foo();";
+  TU.AdditionalFiles["a.h"] = "void a();";
+  TU.AdditionalFiles["b.h"] = "void b();";
+  TU.AdditionalFiles["dir/c.h"] = "void c();";
+  TU.AdditionalFiles["unused.h"] = "void unused();";
+  TU.AdditionalFiles["dir/unused.h"] = "void dirUnused();";
+  TU.AdditionalFiles["not_included.h"] = "void notIncluded();";
+  TU.ExtraArgs = {"-I" + testPath("dir")};
+  TU.Code = MainFile.str();
+  ParsedAST AST = TU.build();
+  auto UnusedIncludes = computeUnusedIncludes(AST);
+  std::vector UnusedHeaders;
+  UnusedHeaders.reserve(UnusedIncludes.size());
+  for (const auto &Include : UnusedIncludes) {
+// Strip enclosing "".
+UnusedHeaders.push_back(
+Include->Written.substr(1, Include->Written.size() - 2));
+  }
+  EXPECT_THAT(UnusedHeaders, UnorderedElementsAre("unused.h", "dir/unused.h"));
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/ParsedAST.h
===
--- clang-tools-extra/clangd/ParsedAST.h
+++ clang-tools-extra/clangd/ParsedAST.h
@@ -159,6 +159,8 @@
   std::unique_ptr Resolver;
 };
 
+std::vector computeUnusedIncludes(ParsedAST &AST);
+
 } // namespace clangd
 } // namespace clang
 
Index: clang-tools-extra/clangd/ParsedAST.cpp
===
--- clang-tools-extra/clangd/ParsedAST.cpp
+++ clang-tools-extra/clangd/ParsedAST.cpp
@@ -18,6 +18,7 @@
 #include "FeatureModule.h"
 #include "Headers.h"
 #include "HeuristicResolver.h"
+#include "IncludeCleaner.h"
 #include "IncludeFixer.h"
 #include "Preamble.h"
 #include "SourceCode.h"
@@ -624,5 +625,15 @@
 return llvm::None;
   return llvm::StringRef(Preamble->Version);
 }
+
+std::vector computeUnusedIncludes(ParsedAST &AST) {
+  const auto &SM = AST.getSourceManager();
+
+  auto Refs = findReferencedLocations(AST);
+  auto ReferencedFiles = translateToHeaderIDs(findReferencedFiles(Refs, SM),
+  AST.getIncludeStructure(), SM);
+  return getUnused(AST.getIncludeStructure(), ReferencedFiles, SM);
+}
+
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/IncludeCleaner.h
===
--- clang-tools-extra/clangd/IncludeCleaner.h
+++ clang-tools-extra/clangd/IncludeCleaner.h
@@ -25,6 +25,7 @@
 #include "ParsedAST.h"
 #include "clang/Basic/SourceLocation.h"
 #include "llvm/ADT/DenseSet.h"
+#include 
 
 namespace clang {
 namespace clangd {
@@ -46,6 +47,21 @@
 /// - err on the side of reporting all possible locations
 ReferencedLocations findReferencedLocations(ParsedAST &AST);
 
+/// Retrieves IDs of all files containing SourceLocations from \p Locs.
+llvm::DenseSet findReferencedFiles(const ReferencedLocations &Locs,
+   const SourceManager &SM);
+
+/// Maps FileIDs to the internal IncludeStructure representation (HeaderIDs).
+llvm::DenseSet
+translateToHeaderIDs(const llvm::DenseSet &Files,
+ const IncludeStructure &Includes, const SourceManager &SM);
+
+/// Retrieves headers that are referenced from the main file but not used.
+std::vector
+getUnused(const IncludeStructure &Includes,
+  const llvm::DenseSet &ReferencedFiles,
+  const SourceManager &SM);
+
 } // namespace clangd
 } // namespace clang
 
Index: clang-tools-extra/clangd/IncludeCleaner.cpp
===
---

[PATCH] D111081: [clang] [MinGW] Fix paths on Gentoo

2021-10-05 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added a reviewer: mstorsjo.
mstorsjo added a subscriber: cfe-commits.
mstorsjo added a comment.

(I’ll have a look and comment on the patch later.)


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

https://reviews.llvm.org/D111081

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


[PATCH] D110455: DebugInfo: Use clang's preferred names for integer types

2021-10-05 Thread Paul Robinson via Phabricator via cfe-commits
probinson accepted this revision.
probinson added a comment.
This revision is now accepted and ready to land.

Seems like a good simplification. LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110455

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


[PATCH] D111078: [AIX] Enable int128 in 64 bit mode

2021-10-05 Thread Jinsong Ji via Phabricator via cfe-commits
jsji added inline comments.



Comment at: llvm/test/CodeGen/PowerPC/int128_ldst.ll:31
 ; CHECK-NEXT:mr 3, 5
 ; CHECK-NEXT:blr
 entry:

hubert.reinterpretcast wrote:
> Confirming that this case matches GCC on AIX:
> ```
> ld 4,8(3)
> ld 3,0(3)
> blr
> ```
$ gcc -maix64 -S -O p128.c -o t.s; grep blr -B3 t.s
.check1:
ld 4,8(3)
ld 3,0(3)
blr



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111078

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


[PATCH] D110656: [clang][Sema] Warn on uninitialized array elments

2021-10-05 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D110656#3034971 , @beanz wrote:

> In D110656#3034083 , @xbolva00 
> wrote:
>
>> Why just no special case "= {0};" pattern and do not warn in that case?
>
> This case did show up, but was not the majority of issues for LLVM (although 
> might be the majority we care about). The related `= {nullptr};` pattern also 
> shows a few times.
>
>> If there are more patterns, take it from other side - pick patterns where 
>> you are sure that they are wrong and developer needs to fix them and emit 
>> warnings for them.
>
> There are a bunch of places (particularly in LLVM instruction matching), 
> where LLVM generates data structures with statically sized arrays that hold 
> the maximum possible values, and rely on zero-initialized values to denote 
> the end of the used space.
>
> For the tablegen-genreated code wrapping in `pragma`s to disable the warning 
> works, but there isn't really a good way that I can think of to not emit a 
> warning for an array of 10 elements where we provide 6 in a general case 
> while also warning on the actual potential bug.

This was the kind of thing I was worried about. I expect that this pattern also 
shows up (perhaps less frequently) in non-generated code as well.

> In D110656#3034149 , @xbolva00 
> wrote:
>
>> If possible, @beanz could share list of new warnings from LLVM build here?
>
> The big offenders were the tablegen-generated asm and register matchers and 
> the target files under clang/lib/Basic/Targets. Those accounted for filling 
> my scroll back buffer a few times over...
>
> I'm running a new build now disabling the warning int he clang target files 
> to see how that shapes up. Will share what I find.

Thanks, I'm curious to hear what you find!

Another alternative to surfacing this as a frontend warning is to make a 
`bugprone` check for clang-tidy as the false positive rate seems likely to be 
more suited to that tool.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110656

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


[PATCH] D110833: [clang-format] Add ControlStatementsAndFunctionDefinitionsExceptControlMacros option to SpaceBeforeParens

2021-10-05 Thread Christian Rayroud via Phabricator via cfe-commits
crayroud added a comment.

Thank you for your inputs. I will work on the changes and update the patch once 
it is ready.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110833

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


[PATCH] D111078: [AIX] Enable int128 in 64 bit mode

2021-10-05 Thread David Tenty via Phabricator via cfe-commits
daltenty added a comment.

> Making a change to whether a platform has __int128 affects the ABI of 
> libc++'s std::chrono::file_clock. We should make sure the mitigation patch is 
> posted and accepted.

Good point, but the std::chrono::file_clock interface hasn't shipped yet on the 
platform libc++, since it's currently still at a bit of a backlevel, so I don't 
think that should be blocking to enabling the type.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111078

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


[PATCH] D111078: [AIX] Enable int128 in 64 bit mode

2021-10-05 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added a comment.

In D111078#3042913 , @daltenty wrote:

> Good point, but the std::chrono::file_clock interface hasn't shipped yet on 
> the platform libc++, since it's currently still at a bit of a backlevel, so I 
> don't think that should be blocking to enabling the type.

I am concerned that `__int128` is an over-aligned type on AIX. The required 
alignment of the type is greater than the greatest fundamental alignment 
supported by default on the platform.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111078

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


[PATCH] D108194: [clangd] IncludeCleaner: Mark used headers

2021-10-05 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added inline comments.
This revision is now accepted and ready to land.



Comment at: clang-tools-extra/clangd/Headers.h:65
   SrcMgr::CharacteristicKind FileKind = SrcMgr::C_User;
+  unsigned ID = std::numeric_limits::max(); // Corresponding 
HeaderID.
 };

I don't think we're under any size pressure here - `Optional`?



Comment at: clang-tools-extra/clangd/Headers.h:65
   SrcMgr::CharacteristicKind FileKind = SrcMgr::C_User;
+  unsigned ID = std::numeric_limits::max(); // Corresponding 
HeaderID.
 };

sammccall wrote:
> I don't think we're under any size pressure here - `Optional`?
call the member HeaderID, rather than have this as a comment only?



Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:161
+  const llvm::DenseSet &ReferencedFiles,
+  const SourceManager &SM) {
+  std::vector Unused;

SM is unused



Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:165
+// FIXME: Skip includes that are not self-contained.
+if (MFI.Resolved.empty()) {
+  elog("{0} is unresolved", MFI.Written);

this can just be a check whether MFI.ID is valid or not



Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:171
+assert(IncludeID != IncludeStructure::HeaderID::Invalid);
+bool Used = ReferencedFiles.find(IncludeID) != ReferencedFiles.end();
+if (!Used) {

ReferencedFiles.contains(IncludeID) and inline into the if?



Comment at: clang-tools-extra/clangd/ParsedAST.h:162
 
+std::vector computeUnusedIncludes(ParsedAST &AST);
+

I think this function belongs in IncludeCleaner.h.

(There's a circularity problem between ParsedAST and IncludeCleaner, but 
putting the function here doesn't fix it)



Comment at: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp:165
+  for (const auto &Include : UnusedIncludes) {
+// Strip enclosing "".
+UnusedHeaders.push_back(

Don't bother doing this stripping just for the test IMO, it obscures the 
assertion (more than escaping quotes would)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108194

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


[PATCH] D108194: [clangd] IncludeCleaner: Mark used headers

2021-10-05 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 377264.
kbobyrev marked 6 inline comments as done.
kbobyrev added a comment.

Thank you for the review! Looks much better now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108194

Files:
  clang-tools-extra/clangd/Headers.cpp
  clang-tools-extra/clangd/Headers.h
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/IncludeCleaner.h
  clang-tools-extra/clangd/ParsedAST.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
@@ -16,6 +16,8 @@
 namespace clangd {
 namespace {
 
+using ::testing::UnorderedElementsAre;
+
 TEST(IncludeCleaner, ReferencedLocations) {
   struct TestCase {
 std::string HeaderCode;
@@ -131,6 +133,40 @@
   }
 }
 
+TEST(IncludeCleaner, GetUnusedHeaders) {
+  llvm::StringLiteral MainFile = R"cpp(
+#include "a.h"
+#include "b.h"
+#include "dir/c.h"
+#include "dir/unused.h"
+#include "unused.h"
+void foo() {
+  a();
+  b();
+  c();
+})cpp";
+  // Build expected ast with symbols coming from headers.
+  TestTU TU;
+  TU.Filename = "foo.cpp";
+  TU.AdditionalFiles["foo.h"] = "void foo();";
+  TU.AdditionalFiles["a.h"] = "void a();";
+  TU.AdditionalFiles["b.h"] = "void b();";
+  TU.AdditionalFiles["dir/c.h"] = "void c();";
+  TU.AdditionalFiles["unused.h"] = "void unused();";
+  TU.AdditionalFiles["dir/unused.h"] = "void dirUnused();";
+  TU.AdditionalFiles["not_included.h"] = "void notIncluded();";
+  TU.ExtraArgs = {"-I" + testPath("dir")};
+  TU.Code = MainFile.str();
+  ParsedAST AST = TU.build();
+  auto UnusedIncludes = computeUnusedIncludes(AST);
+  std::vector UnusedHeaders;
+  UnusedHeaders.reserve(UnusedIncludes.size());
+  for (const auto &Include : UnusedIncludes)
+UnusedHeaders.push_back(Include->Written);
+  EXPECT_THAT(UnusedHeaders,
+  UnorderedElementsAre("\"unused.h\"", "\"dir/unused.h\""));
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/ParsedAST.cpp
===
--- clang-tools-extra/clangd/ParsedAST.cpp
+++ clang-tools-extra/clangd/ParsedAST.cpp
@@ -18,6 +18,7 @@
 #include "FeatureModule.h"
 #include "Headers.h"
 #include "HeuristicResolver.h"
+#include "IncludeCleaner.h"
 #include "IncludeFixer.h"
 #include "Preamble.h"
 #include "SourceCode.h"
@@ -624,5 +625,6 @@
 return llvm::None;
   return llvm::StringRef(Preamble->Version);
 }
+
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/IncludeCleaner.h
===
--- clang-tools-extra/clangd/IncludeCleaner.h
+++ clang-tools-extra/clangd/IncludeCleaner.h
@@ -25,6 +25,7 @@
 #include "ParsedAST.h"
 #include "clang/Basic/SourceLocation.h"
 #include "llvm/ADT/DenseSet.h"
+#include 
 
 namespace clang {
 namespace clangd {
@@ -46,6 +47,22 @@
 /// - err on the side of reporting all possible locations
 ReferencedLocations findReferencedLocations(ParsedAST &AST);
 
+/// Retrieves IDs of all files containing SourceLocations from \p Locs.
+llvm::DenseSet findReferencedFiles(const ReferencedLocations &Locs,
+   const SourceManager &SM);
+
+/// Maps FileIDs to the internal IncludeStructure representation (HeaderIDs).
+llvm::DenseSet
+translateToHeaderIDs(const llvm::DenseSet &Files,
+ const IncludeStructure &Includes, const SourceManager &SM);
+
+/// Retrieves headers that are referenced from the main file but not used.
+std::vector
+getUnused(const IncludeStructure &Includes,
+  const llvm::DenseSet &ReferencedFiles);
+
+std::vector computeUnusedIncludes(ParsedAST &AST);
+
 } // namespace clangd
 } // namespace clang
 
Index: clang-tools-extra/clangd/IncludeCleaner.cpp
===
--- clang-tools-extra/clangd/IncludeCleaner.cpp
+++ clang-tools-extra/clangd/IncludeCleaner.cpp
@@ -98,6 +98,35 @@
   llvm::DenseSet Visited;
 };
 
+// Given a set of referenced FileIDs, determines all the potentially-referenced
+// files and macros by traversing expansion/spelling locations of macro IDs.
+// This is used to map the referenced SourceLocations onto real files.
+struct ReferencedFiles {
+  ReferencedFiles(const SourceManager &SM) : SM(SM) {}
+  llvm::DenseSet Files;
+  llvm::DenseSet Macros;
+  const SourceManager &SM;
+
+  void add(SourceLocation Loc) { add(SM.getFileID(Loc), Loc); }
+
+  void add(FileID FID, SourceLocation Loc) {
+if (FID.isInvalid())
+  return;
+assert(SM.isInFileID(Loc, FID));
+if (Loc.isFileID()) {
+  Files.insert(FID);
+

[clang-tools-extra] 6831c1d - [clangd] Include refs of base method in refs for derived method.

2021-10-05 Thread Utkarsh Saxena via cfe-commits

Author: Utkarsh Saxena
Date: 2021-10-05T17:39:49+02:00
New Revision: 6831c1d8689bebe745aac1fdd7354c2e2f692c1a

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

LOG: [clangd] Include refs of base method in refs for derived method.

Addresses https://github.com/clangd/clangd/issues/881

Includes refs of base class method in refs of derived class method.
Previously we reported base class method's refs only for decl of derived
class method. Ideally this should work for all usages of derived class method.

Related patch:
https://github.com/llvm/llvm-project/commit/fbeff2ec2bc6e44b92931207b0063f83ff7a3b3a.

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

Added: 


Modified: 
clang-tools-extra/clangd/XRefs.cpp
clang-tools-extra/clangd/unittests/XRefsTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/XRefs.cpp 
b/clang-tools-extra/clangd/XRefs.cpp
index ea61cba460efc..85c6b7b771fce 100644
--- a/clang-tools-extra/clangd/XRefs.cpp
+++ b/clang-tools-extra/clangd/XRefs.cpp
@@ -1391,13 +1391,11 @@ ReferencesResult findReferences(ParsedAST &AST, 
Position Pos, uint32_t Limit,
 // Special case: For virtual methods, report decl/def of overrides and
 // references to all overridden methods in complete type hierarchy.
 if (const auto *CMD = llvm::dyn_cast(ND)) {
-  if (CMD->isVirtual())
-if (IdentifierAtCursor && SM.getSpellingLoc(CMD->getLocation()) ==
-  IdentifierAtCursor->location()) {
-  if (auto ID = getSymbolID(CMD))
-OverriddenBy.Subjects.insert(ID);
-  getOverriddenMethods(CMD, OverriddenMethods);
-}
+  if (CMD->isVirtual()) {
+if (auto ID = getSymbolID(CMD))
+  OverriddenBy.Subjects.insert(ID);
+getOverriddenMethods(CMD, OverriddenMethods);
+  }
 }
   }
 }

diff  --git a/clang-tools-extra/clangd/unittests/XRefsTests.cpp 
b/clang-tools-extra/clangd/unittests/XRefsTests.cpp
index e8b64e9200bb5..1f41dcd69913c 100644
--- a/clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ b/clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -1780,11 +1780,13 @@ void checkFindRefs(llvm::StringRef Test, bool UseIndex 
= false) {
 AllOf(RangeIs(R), AttrsAre(ReferencesResult::Declaration |
ReferencesResult::Definition |
ReferencesResult::Override)));
-  EXPECT_THAT(
-  findReferences(AST, T.point(), 0, UseIndex ? TU.index().get() : nullptr)
-  .References,
-  UnorderedElementsAreArray(ExpectedLocations))
-  << Test;
+  for (const auto &P : T.points()) {
+EXPECT_THAT(findReferences(AST, P, 0, UseIndex ? TU.index().get() : 
nullptr)
+.References,
+UnorderedElementsAreArray(ExpectedLocations))
+<< "Failed for Refs at " << P << "\n"
+<< Test;
+  }
 }
 
 TEST(FindReferences, WithinAST) {
@@ -1961,7 +1963,7 @@ TEST(FindReferences, IncludeOverrides) {
   R"cpp(
 class Base {
 public:
-  virtual void $decl[[f^unc]]() = 0;
+  virtu^al void $decl[[f^unc]]() ^= ^0;
 };
 class Derived : public Base {
 public:
@@ -1990,13 +1992,13 @@ TEST(FindReferences, RefsToBaseMethod) {
 };
 class Derived : public Base {
 public:
-  void $decl[[fu^nc]]() override;
+  void $decl[[fu^nc]]() over^ride;
 };
 void test(BaseBase* BB, Base* B, Derived* D) {
   // refs to overridden methods in complete type hierarchy are 
reported.
   BB->[[func]]();
   B->[[func]]();
-  D->[[func]]();
+  D->[[fu^nc]]();
 })cpp";
   checkFindRefs(Test, /*UseIndex=*/true);
 }



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


[PATCH] D111039: [clangd] Include refs of base method in refs for derived method.

2021-10-05 Thread Utkarsh Saxena via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6831c1d8689b: [clangd] Include refs of base method in refs 
for derived method. (authored by usaxena95).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111039

Files:
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/unittests/XRefsTests.cpp


Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -1780,11 +1780,13 @@
 AllOf(RangeIs(R), AttrsAre(ReferencesResult::Declaration |
ReferencesResult::Definition |
ReferencesResult::Override)));
-  EXPECT_THAT(
-  findReferences(AST, T.point(), 0, UseIndex ? TU.index().get() : nullptr)
-  .References,
-  UnorderedElementsAreArray(ExpectedLocations))
-  << Test;
+  for (const auto &P : T.points()) {
+EXPECT_THAT(findReferences(AST, P, 0, UseIndex ? TU.index().get() : 
nullptr)
+.References,
+UnorderedElementsAreArray(ExpectedLocations))
+<< "Failed for Refs at " << P << "\n"
+<< Test;
+  }
 }
 
 TEST(FindReferences, WithinAST) {
@@ -1961,7 +1963,7 @@
   R"cpp(
 class Base {
 public:
-  virtual void $decl[[f^unc]]() = 0;
+  virtu^al void $decl[[f^unc]]() ^= ^0;
 };
 class Derived : public Base {
 public:
@@ -1990,13 +1992,13 @@
 };
 class Derived : public Base {
 public:
-  void $decl[[fu^nc]]() override;
+  void $decl[[fu^nc]]() over^ride;
 };
 void test(BaseBase* BB, Base* B, Derived* D) {
   // refs to overridden methods in complete type hierarchy are 
reported.
   BB->[[func]]();
   B->[[func]]();
-  D->[[func]]();
+  D->[[fu^nc]]();
 })cpp";
   checkFindRefs(Test, /*UseIndex=*/true);
 }
Index: clang-tools-extra/clangd/XRefs.cpp
===
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -1391,13 +1391,11 @@
 // Special case: For virtual methods, report decl/def of overrides and
 // references to all overridden methods in complete type hierarchy.
 if (const auto *CMD = llvm::dyn_cast(ND)) {
-  if (CMD->isVirtual())
-if (IdentifierAtCursor && SM.getSpellingLoc(CMD->getLocation()) ==
-  IdentifierAtCursor->location()) {
-  if (auto ID = getSymbolID(CMD))
-OverriddenBy.Subjects.insert(ID);
-  getOverriddenMethods(CMD, OverriddenMethods);
-}
+  if (CMD->isVirtual()) {
+if (auto ID = getSymbolID(CMD))
+  OverriddenBy.Subjects.insert(ID);
+getOverriddenMethods(CMD, OverriddenMethods);
+  }
 }
   }
 }


Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -1780,11 +1780,13 @@
 AllOf(RangeIs(R), AttrsAre(ReferencesResult::Declaration |
ReferencesResult::Definition |
ReferencesResult::Override)));
-  EXPECT_THAT(
-  findReferences(AST, T.point(), 0, UseIndex ? TU.index().get() : nullptr)
-  .References,
-  UnorderedElementsAreArray(ExpectedLocations))
-  << Test;
+  for (const auto &P : T.points()) {
+EXPECT_THAT(findReferences(AST, P, 0, UseIndex ? TU.index().get() : nullptr)
+.References,
+UnorderedElementsAreArray(ExpectedLocations))
+<< "Failed for Refs at " << P << "\n"
+<< Test;
+  }
 }
 
 TEST(FindReferences, WithinAST) {
@@ -1961,7 +1963,7 @@
   R"cpp(
 class Base {
 public:
-  virtual void $decl[[f^unc]]() = 0;
+  virtu^al void $decl[[f^unc]]() ^= ^0;
 };
 class Derived : public Base {
 public:
@@ -1990,13 +1992,13 @@
 };
 class Derived : public Base {
 public:
-  void $decl[[fu^nc]]() override;
+  void $decl[[fu^nc]]() over^ride;
 };
 void test(BaseBase* BB, Base* B, Derived* D) {
   // refs to overridden methods in complete type hierarchy are reported.
   BB->[[func]]();
   B->[[func]]();
-  D->[[func]]();
+  D->[[fu^nc]]();
 })cpp";
   checkFindRefs(Test, /*UseIndex=*/true);
 }
Index: clang-tools-extra/clangd/XRefs.cpp
===
--- clang-to

[PATCH] D111062: [RISCV] Rename some assembler mnemonic and intrinsic functions for RVV 1.0.

2021-10-05 Thread Fraser Cormack via Phabricator via cfe-commits
frasercrmck added a comment.

LGTM in general. My comments are all about comments. I know the old names are 
kept as aliases but I still think it's better to reference the "real" 
instructions where we can.




Comment at: llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp:2468
 //  pseudoinstruction: vmsge{u}.vx vd, va, x, v0.t, vt
 //  expansion: vmslt{u}.vx vt, va, x;  vmandnot.mm vd, vd, vt
 assert(Inst.getOperand(0).getReg() == RISCV::V0 &&

Comment here



Comment at: llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp:2486
 // pseudoinstruction: vmsge{u}.vx vd, va, x, v0.t, vt
 // expansion: vmslt{u}.vx vt, va, x; vmandnot.mm vt, v0, vt; vmandnot.mm 
vd,
 // vd, v0; vmor.mm vd, vt, vd

Comment here too



Comment at: llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp:896
   // If the MaskedOff value and the Mask are the same value use
   // vmslt{u}.vx vt, va, x;  vmandnot.mm vd, vd, vt
   // This avoids needing to copy v0 to vd before starting the next 
sequence.

Comment needs updating



Comment at: llvm/lib/Target/RISCV/RISCVISelLowering.cpp:4167
   case ISD::VP_REDUCE_AND: {
 // vpopc ~x == 0
 SDValue TrueMask = DAG.getNode(RISCVISD::VMSET_VL, DL, ContainerVT, VL);

Comment needs updating here and below



Comment at: llvm/lib/Target/RISCV/RISCVISelLowering.cpp:4201
   // Note that we must return the start value when no elements are operated
   // upon. The vpopc instructions we've emitted in each case above will return
   // 0 for an inactive vector, and so we've already received the neutral value:

Stale mnemonic name here



Comment at: llvm/lib/Target/RISCV/RISCVISelLowering.h:266
 
   //  vpopc.m with additional mask and VL operands.
+  VCPOP_VL,

Nit: comment needs updating too


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111062

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


[clang] 9503ad3 - [clang] FatalErrorHandler.cpp - add explicit include

2021-10-05 Thread Simon Pilgrim via cfe-commits

Author: Simon Pilgrim
Date: 2021-10-05T17:03:17+01:00
New Revision: 9503ad3b533cb84b51cfc80c51d262da50435013

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

LOG: [clang] FatalErrorHandler.cpp - add explicit  include

Required for fprintf/stderr usage in the error handler, noticed while trying to 
remove the  dependency described in D111049

Added: 


Modified: 
clang/tools/libclang/FatalErrorHandler.cpp

Removed: 




diff  --git a/clang/tools/libclang/FatalErrorHandler.cpp 
b/clang/tools/libclang/FatalErrorHandler.cpp
index 73864754c065..506b047c1b13 100644
--- a/clang/tools/libclang/FatalErrorHandler.cpp
+++ b/clang/tools/libclang/FatalErrorHandler.cpp
@@ -9,6 +9,7 @@
 
 #include "clang-c/FatalErrorHandler.h"
 #include "llvm/Support/ErrorHandling.h"
+#include 
 #include 
 
 static void aborting_fatal_error_handler(void *, const char *reason,



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


[clang-tools-extra] ebfcd06 - [clangd] IncludeCleaner: Mark used headers

2021-10-05 Thread Kirill Bobyrev via cfe-commits

Author: Kirill Bobyrev
Date: 2021-10-05T18:08:24+02:00
New Revision: ebfcd06d422286dcdd0e9a8c57e207a46c8fb8fb

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

LOG: [clangd] IncludeCleaner: Mark used headers

Follow-up on D105426.

Reviewed By: sammccall

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

Added: 


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

Removed: 




diff  --git a/clang-tools-extra/clangd/Headers.cpp 
b/clang-tools-extra/clangd/Headers.cpp
index 5946180f346d..9f5ab244aa63 100644
--- a/clang-tools-extra/clangd/Headers.cpp
+++ b/clang-tools-extra/clangd/Headers.cpp
@@ -56,6 +56,8 @@ class RecordHeaders : public PPCallbacks {
   SM.getLineNumber(SM.getFileID(HashLoc), Inc.HashOffset) - 1;
   Inc.FileKind = FileKind;
   Inc.Directive = IncludeTok.getIdentifierInfo()->getPPKeywordID();
+  if (File)
+Inc.HeaderID = static_cast(Out->getOrCreateID(File));
 }
 
 // Record include graph (not just for main-file includes)

diff  --git a/clang-tools-extra/clangd/Headers.h 
b/clang-tools-extra/clangd/Headers.h
index 513e21d62088..815131572eac 100644
--- a/clang-tools-extra/clangd/Headers.h
+++ b/clang-tools-extra/clangd/Headers.h
@@ -61,6 +61,7 @@ struct Inclusion {
   unsigned HashOffset = 0; // Byte offset from start of file to #.
   int HashLine = 0;// Line number containing the directive, 0-indexed.
   SrcMgr::CharacteristicKind FileKind = SrcMgr::C_User;
+  llvm::Optional HeaderID;
 };
 llvm::raw_ostream &operator<<(llvm::raw_ostream &, const Inclusion &);
 bool operator==(const Inclusion &LHS, const Inclusion &RHS);

diff  --git a/clang-tools-extra/clangd/IncludeCleaner.cpp 
b/clang-tools-extra/clangd/IncludeCleaner.cpp
index dbf19d4e08f9..d9bf600a04b8 100644
--- a/clang-tools-extra/clangd/IncludeCleaner.cpp
+++ b/clang-tools-extra/clangd/IncludeCleaner.cpp
@@ -98,6 +98,35 @@ class ReferencedLocationCrawler
   llvm::DenseSet Visited;
 };
 
+// Given a set of referenced FileIDs, determines all the potentially-referenced
+// files and macros by traversing expansion/spelling locations of macro IDs.
+// This is used to map the referenced SourceLocations onto real files.
+struct ReferencedFiles {
+  ReferencedFiles(const SourceManager &SM) : SM(SM) {}
+  llvm::DenseSet Files;
+  llvm::DenseSet Macros;
+  const SourceManager &SM;
+
+  void add(SourceLocation Loc) { add(SM.getFileID(Loc), Loc); }
+
+  void add(FileID FID, SourceLocation Loc) {
+if (FID.isInvalid())
+  return;
+assert(SM.isInFileID(Loc, FID));
+if (Loc.isFileID()) {
+  Files.insert(FID);
+  return;
+}
+// Don't process the same macro FID twice.
+if (!Macros.insert(FID).second)
+  return;
+const auto &Exp = SM.getSLocEntry(FID).getExpansion();
+add(Exp.getSpellingLoc());
+add(Exp.getExpansionLocStart());
+add(Exp.getExpansionLocEnd());
+  }
+};
+
 } // namespace
 
 ReferencedLocations findReferencedLocations(ParsedAST &AST) {
@@ -108,5 +137,65 @@ ReferencedLocations findReferencedLocations(ParsedAST 
&AST) {
   return Result;
 }
 
+llvm::DenseSet
+findReferencedFiles(const llvm::DenseSet &Locs,
+const SourceManager &SM) {
+  std::vector Sorted{Locs.begin(), Locs.end()};
+  llvm::sort(Sorted); // Group by FileID.
+  ReferencedFiles Result(SM);
+  for (auto It = Sorted.begin(); It < Sorted.end();) {
+FileID FID = SM.getFileID(*It);
+Result.add(FID, *It);
+// Cheaply skip over all the other locations from the same FileID.
+// This avoids lots of redundant Loc->File lookups for the same file.
+do
+  ++It;
+while (It != Sorted.end() && SM.isInFileID(*It, FID));
+  }
+  return std::move(Result.Files);
+}
+
+std::vector
+getUnused(const IncludeStructure &Structure,
+  const llvm::DenseSet &ReferencedFiles) {
+  std::vector Unused;
+  for (const Inclusion &MFI : Structure.MainFileIncludes) {
+// FIXME: Skip includes that are not self-contained.
+assert(MFI.HeaderID);
+auto IncludeID = static_cast(*MFI.HeaderID);
+if (!ReferencedFiles.contains(IncludeID)) {
+  Unused.push_back(&MFI);
+}
+dlog("{0} is {1}", MFI.Written,
+ ReferencedFiles.contains(IncludeID) ? "USED" : "UNUSED");
+  }
+  return Unused;
+}
+
+llvm::DenseSet
+translateToHeaderIDs(const llvm::DenseSet &Files,
+ const IncludeStructure &Includes,
+ const SourceManager &SM) {
+  llvm::DenseSet TranslatedHeaderIDs;
+  TranslatedHeaderIDs.reserve(Files.size());
+  for (FileID FID : Fil

[PATCH] D108194: [clangd] IncludeCleaner: Mark used headers

2021-10-05 Thread Kirill Bobyrev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGebfcd06d4222: [clangd] IncludeCleaner: Mark used headers 
(authored by kbobyrev).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108194

Files:
  clang-tools-extra/clangd/Headers.cpp
  clang-tools-extra/clangd/Headers.h
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/IncludeCleaner.h
  clang-tools-extra/clangd/ParsedAST.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
@@ -16,6 +16,8 @@
 namespace clangd {
 namespace {
 
+using ::testing::UnorderedElementsAre;
+
 TEST(IncludeCleaner, ReferencedLocations) {
   struct TestCase {
 std::string HeaderCode;
@@ -131,6 +133,40 @@
   }
 }
 
+TEST(IncludeCleaner, GetUnusedHeaders) {
+  llvm::StringLiteral MainFile = R"cpp(
+#include "a.h"
+#include "b.h"
+#include "dir/c.h"
+#include "dir/unused.h"
+#include "unused.h"
+void foo() {
+  a();
+  b();
+  c();
+})cpp";
+  // Build expected ast with symbols coming from headers.
+  TestTU TU;
+  TU.Filename = "foo.cpp";
+  TU.AdditionalFiles["foo.h"] = "void foo();";
+  TU.AdditionalFiles["a.h"] = "void a();";
+  TU.AdditionalFiles["b.h"] = "void b();";
+  TU.AdditionalFiles["dir/c.h"] = "void c();";
+  TU.AdditionalFiles["unused.h"] = "void unused();";
+  TU.AdditionalFiles["dir/unused.h"] = "void dirUnused();";
+  TU.AdditionalFiles["not_included.h"] = "void notIncluded();";
+  TU.ExtraArgs = {"-I" + testPath("dir")};
+  TU.Code = MainFile.str();
+  ParsedAST AST = TU.build();
+  auto UnusedIncludes = computeUnusedIncludes(AST);
+  std::vector UnusedHeaders;
+  UnusedHeaders.reserve(UnusedIncludes.size());
+  for (const auto &Include : UnusedIncludes)
+UnusedHeaders.push_back(Include->Written);
+  EXPECT_THAT(UnusedHeaders,
+  UnorderedElementsAre("\"unused.h\"", "\"dir/unused.h\""));
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/ParsedAST.cpp
===
--- clang-tools-extra/clangd/ParsedAST.cpp
+++ clang-tools-extra/clangd/ParsedAST.cpp
@@ -18,6 +18,7 @@
 #include "FeatureModule.h"
 #include "Headers.h"
 #include "HeuristicResolver.h"
+#include "IncludeCleaner.h"
 #include "IncludeFixer.h"
 #include "Preamble.h"
 #include "SourceCode.h"
@@ -624,5 +625,6 @@
 return llvm::None;
   return llvm::StringRef(Preamble->Version);
 }
+
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/IncludeCleaner.h
===
--- clang-tools-extra/clangd/IncludeCleaner.h
+++ clang-tools-extra/clangd/IncludeCleaner.h
@@ -25,6 +25,7 @@
 #include "ParsedAST.h"
 #include "clang/Basic/SourceLocation.h"
 #include "llvm/ADT/DenseSet.h"
+#include 
 
 namespace clang {
 namespace clangd {
@@ -46,6 +47,22 @@
 /// - err on the side of reporting all possible locations
 ReferencedLocations findReferencedLocations(ParsedAST &AST);
 
+/// Retrieves IDs of all files containing SourceLocations from \p Locs.
+llvm::DenseSet findReferencedFiles(const ReferencedLocations &Locs,
+   const SourceManager &SM);
+
+/// Maps FileIDs to the internal IncludeStructure representation (HeaderIDs).
+llvm::DenseSet
+translateToHeaderIDs(const llvm::DenseSet &Files,
+ const IncludeStructure &Includes, const SourceManager &SM);
+
+/// Retrieves headers that are referenced from the main file but not used.
+std::vector
+getUnused(const IncludeStructure &Includes,
+  const llvm::DenseSet &ReferencedFiles);
+
+std::vector computeUnusedIncludes(ParsedAST &AST);
+
 } // namespace clangd
 } // namespace clang
 
Index: clang-tools-extra/clangd/IncludeCleaner.cpp
===
--- clang-tools-extra/clangd/IncludeCleaner.cpp
+++ clang-tools-extra/clangd/IncludeCleaner.cpp
@@ -98,6 +98,35 @@
   llvm::DenseSet Visited;
 };
 
+// Given a set of referenced FileIDs, determines all the potentially-referenced
+// files and macros by traversing expansion/spelling locations of macro IDs.
+// This is used to map the referenced SourceLocations onto real files.
+struct ReferencedFiles {
+  ReferencedFiles(const SourceManager &SM) : SM(SM) {}
+  llvm::DenseSet Files;
+  llvm::DenseSet Macros;
+  const SourceManager &SM;
+
+  void add(SourceLocation Loc) { add(SM.getFileID(Loc), Loc); }
+
+  void add(FileID FID, SourceLocation Loc) {
+if (FID.isInvalid())
+  return;
+assert(SM.isInFileID(Loc, FID));
+if (Loc.isFileID()) {
+  Files.insert

[PATCH] D110600: [clang-tidy] Fix add_new_check.py to generate correct list.rst autofix column from relative path

2021-10-05 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev added a comment.

Sure! I'm just using the credentials from the arc, mostly, i.e. `arc patch 
--nobranch D110600 && git push`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110600

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


[clang-tools-extra] 32ab79e - [clang-tidy] Fix add_new_check.py to generate correct list.rst autofix column from relative path

2021-10-05 Thread Kirill Bobyrev via cfe-commits

Author: Matt Beardsley
Date: 2021-10-05T18:09:53+02:00
New Revision: 32ab79ebc496d73cb0eb3ad3b54d32b00fc49ba1

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

LOG: [clang-tidy] Fix add_new_check.py to generate correct list.rst autofix 
column from relative path

Previously, the code in add_new_check.py that looks for fixit keywords in check 
source files when generating list.rst assumed that the script would only be 
called from its own path. That means it doesn't find any source files for the 
checks it's attempting to scan for, and it defaults to writing out nothing in 
the "Offers fixes" column for all checks. Other parts of add_new_check.py work 
from other paths, just not this part.

After this fix, add_new_check.py's "offers fixes" column generation for 
list.rst will be consistent regardless of what path it's called from by using 
the caller path that's deduced elsewhere already from sys.argv[0].

Reviewed By: kbobyrev

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/add_new_check.py

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/add_new_check.py 
b/clang-tools-extra/clang-tidy/add_new_check.py
index 0312c04e047c7..a3554b0959759 100755
--- a/clang-tools-extra/clang-tidy/add_new_check.py
+++ b/clang-tools-extra/clang-tidy/add_new_check.py
@@ -323,13 +323,13 @@ def update_checks_list(clang_tidy_path):
   def has_auto_fix(check_name):
 dirname, _, check_name = check_name.partition("-")
 
-checkerCode = get_actual_filename(dirname,
-  get_camel_name(check_name) + '.cpp')
+checker_code = get_actual_filename(os.path.join(clang_tidy_path, dirname),
+   get_camel_name(check_name) + '.cpp')
 
-if not os.path.isfile(checkerCode):
+if not os.path.isfile(checker_code):
   return ""
 
-with io.open(checkerCode, encoding='utf8') as f:
+with io.open(checker_code, encoding='utf8') as f:
   code = f.read()
   if 'FixItHint' in code or "ReplacementText" in code or "fixit" in code:
 # Some simple heuristics to figure out if a checker has an autofix or 
not.



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


[PATCH] D110600: [clang-tidy] Fix add_new_check.py to generate correct list.rst autofix column from relative path

2021-10-05 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 rG32ab79ebc496: [clang-tidy] Fix add_new_check.py to generate 
correct list.rst autofix column… (authored by mattbeardsley, committed by 
kbobyrev).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110600

Files:
  clang-tools-extra/clang-tidy/add_new_check.py


Index: clang-tools-extra/clang-tidy/add_new_check.py
===
--- clang-tools-extra/clang-tidy/add_new_check.py
+++ clang-tools-extra/clang-tidy/add_new_check.py
@@ -323,13 +323,13 @@
   def has_auto_fix(check_name):
 dirname, _, check_name = check_name.partition("-")
 
-checkerCode = get_actual_filename(dirname,
-  get_camel_name(check_name) + '.cpp')
+checker_code = get_actual_filename(os.path.join(clang_tidy_path, dirname),
+   get_camel_name(check_name) + '.cpp')
 
-if not os.path.isfile(checkerCode):
+if not os.path.isfile(checker_code):
   return ""
 
-with io.open(checkerCode, encoding='utf8') as f:
+with io.open(checker_code, encoding='utf8') as f:
   code = f.read()
   if 'FixItHint' in code or "ReplacementText" in code or "fixit" in code:
 # Some simple heuristics to figure out if a checker has an autofix or 
not.


Index: clang-tools-extra/clang-tidy/add_new_check.py
===
--- clang-tools-extra/clang-tidy/add_new_check.py
+++ clang-tools-extra/clang-tidy/add_new_check.py
@@ -323,13 +323,13 @@
   def has_auto_fix(check_name):
 dirname, _, check_name = check_name.partition("-")
 
-checkerCode = get_actual_filename(dirname,
-  get_camel_name(check_name) + '.cpp')
+checker_code = get_actual_filename(os.path.join(clang_tidy_path, dirname),
+   get_camel_name(check_name) + '.cpp')
 
-if not os.path.isfile(checkerCode):
+if not os.path.isfile(checker_code):
   return ""
 
-with io.open(checkerCode, encoding='utf8') as f:
+with io.open(checker_code, encoding='utf8') as f:
   code = f.read()
   if 'FixItHint' in code or "ReplacementText" in code or "fixit" in code:
 # Some simple heuristics to figure out if a checker has an autofix or not.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D110910: [analyzer][solver] Fix CmpOpTable handling bug

2021-10-05 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov added a comment.

Thanks for mentioning me. I'll make a review of this tomorrow.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110910

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


[PATCH] D110600: [clang-tidy] Fix add_new_check.py to generate correct list.rst autofix column from relative path

2021-10-05 Thread Matt Beardsley via Phabricator via cfe-commits
mattbeardsley added a comment.

Works for me! 🙂 I didn't realize you can pull the info automatically from arc. 
Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110600

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


[PATCH] D111134: Add basic aarch64-none-elf bare metal driver.

2021-10-05 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. This looks like it follows the same format as the 
other -none-elf toolchains, and AArch64 can benefit from the bare-metal 
driver for easier access to LLD. Will be worth waiting a few days to see if 
there is any other feedback.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D34

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


[PATCH] D105191: [Clang][OpenMP] Add partial support for Static Device Libraries

2021-10-05 Thread Ye Luo via Phabricator via cfe-commits
ye-luo added inline comments.



Comment at: clang/lib/Driver/ToolChains/CommonArgs.h:62
+ bool postClangLink);
+void AddStaticDeviceLibs(Compilation *C, const Tool *T, const JobAction *JA,
+ const InputInfoList *Inputs, const Driver &D,

ye-luo wrote:
> saiislam wrote:
> > ye-luo wrote:
> > > ye-luo wrote:
> > > > Differentiate the names of all the three AddStaticDeviceLibs functions 
> > > > and add documentation. Be sure to do document every function added in 
> > > > this patch.
> > > @saiislam Fix this?
> > I have added documentation along with function definition in 
> > CommonArgs.cpp. Should I move it here? I thought keep documentation and 
> > code at the same place will improve readability.
> The docs are good. I was looking for "Differentiate the names of all the 
> three AddStaticDeviceLibs functions"
ping @saiislam 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105191

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


Re: [PATCH] D110600: [clang-tidy] Fix add_new_check.py to generate correct list.rst autofix column from relative path

2021-10-05 Thread Kirill Bobyrev via cfe-commits
You're welcome :) Yeah, I think there's even `arc land` that's _intended_
for this but I'm just using the patch option. And it pulls from Phabricator
(name, email etc).

On Tue, Oct 5, 2021 at 6:17 PM Matt Beardsley via Phabricator <
revi...@reviews.llvm.org> wrote:

> mattbeardsley added a comment.
>
> Works for me! 🙂 I didn't realize you can pull the info automatically from
> arc. Thanks!
>
>
> Repository:
>   rG LLVM Github Monorepo
>
> CHANGES SINCE LAST ACTION
>   https://reviews.llvm.org/D110600/new/
>
> https://reviews.llvm.org/D110600
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D111078: [AIX] Enable int128 in 64 bit mode

2021-10-05 Thread Jinsong Ji via Phabricator via cfe-commits
jsji updated this revision to Diff 377283.
jsji added a comment.
Herald added a subscriber: kbarton.

Address comments -- adding AIX triples to more existing tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111078

Files:
  clang/lib/Basic/Targets/OSTargets.h
  clang/test/AST/ast-print-int128.cpp
  clang/test/Analysis/sval-dump-int128.c
  clang/test/CodeGen/dbg-const-int128.c
  clang/test/CodeGen/debug-info.c
  clang/test/CodeGen/extend-arg-64.c
  clang/test/CodeGen/ppc-varargs-struct.c
  clang/test/CodeGen/uint128_t.c
  clang/test/CodeGenCXX/debug-info-enum-i128.cpp
  clang/test/Driver/types.c
  clang/test/Preprocessor/init-ppc64.c
  clang/test/Sema/128bitint.c
  clang/test/Sema/const-eval.c
  clang/test/Sema/redefine_extname.c
  clang/test/Sema/types.c
  llvm/test/CodeGen/PowerPC/int128_ldst.ll

Index: llvm/test/CodeGen/PowerPC/int128_ldst.ll
===
--- llvm/test/CodeGen/PowerPC/int128_ldst.ll
+++ llvm/test/CodeGen/PowerPC/int128_ldst.ll
@@ -17,6 +17,9 @@
 ; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-linux-gnu \
 ; RUN:   -mcpu=pwr8  \
 ; RUN:   < %s | FileCheck %s --check-prefixes=CHECK,CHECK-PREP10,CHECK-P8
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64-ibm-aix-xcoff \
+; RUN:   -mcpu=pwr8  \
+; RUN:   < %s | FileCheck %s --check-prefixes=CHECK,CHECK-PREP10,CHECK-P8
 
 ; Function Attrs: norecurse nounwind readonly uwtable willreturn
 define dso_local i128 @ld_0___int128___int128(i64 %ptr) {
Index: clang/test/Sema/types.c
===
--- clang/test/Sema/types.c
+++ clang/test/Sema/types.c
@@ -3,6 +3,7 @@
 // RUN: %clang_cc1 %s -fblocks -pedantic -verify -triple=x86_64-unknown-linux
 // RUN: %clang_cc1 %s -fblocks -pedantic -verify -triple=x86_64-unknown-linux-gnux32
 // RUN: %clang_cc1 %s -fblocks -pedantic -pedantic -verify -triple=arm64_32-apple-ios7.0
+// RUN: %clang_cc1 %s -fblocks -pedantic -verify -triple=powerpc64-ibm-aix-xcoff
 
 // rdar://6097662
 typedef int (*T)[2];
Index: clang/test/Sema/redefine_extname.c
===
--- clang/test/Sema/redefine_extname.c
+++ clang/test/Sema/redefine_extname.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -triple=x86_64-unknown-linux -Wpragmas -verify %s
+// RUN: %clang_cc1 -triple=powerpc64-ibm-aix-xcoff -Wpragmas -verify %s
 
 // Check that pragma redefine_extname applies to external declarations only.
 #pragma redefine_extname foo_static bar_static
Index: clang/test/Sema/const-eval.c
===
--- clang/test/Sema/const-eval.c
+++ clang/test/Sema/const-eval.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-linux %s -Wno-tautological-pointer-compare -Wno-pointer-to-int-cast
+// RUN: %clang_cc1 -fsyntax-only -verify -triple powerpc64-ibm-aix-xcoff %s -Wno-tautological-pointer-compare -Wno-pointer-to-int-cast
 
 #define EVAL_EXPR(testno, expr) enum { test##testno = (expr) }; struct check_positive##testno { int a[test##testno]; };
 int x;
Index: clang/test/Sema/128bitint.c
===
--- clang/test/Sema/128bitint.c
+++ clang/test/Sema/128bitint.c
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-apple-darwin9 %s -DHAVE
 // RUN: %clang_cc1 -fsyntax-only -verify -triple i686-linux-gnu %s -DHAVE_NOT
+// RUN: %clang_cc1 -fsyntax-only -verify -triple powerpc64-ibm-aix-xcoff %s -DHAVE
+// RUN: %clang_cc1 -fsyntax-only -verify -triple powerpc-ibm-aix-xcoff %s -DHAVE_NOT
 
 #ifdef HAVE
 typedef int i128 __attribute__((__mode__(TI)));
Index: clang/test/Preprocessor/init-ppc64.c
===
--- clang/test/Preprocessor/init-ppc64.c
+++ clang/test/Preprocessor/init-ppc64.c
@@ -811,6 +811,7 @@
 // PPC64-AIX:#define __SIG_ATOMIC_WIDTH__ 32
 // PPC64-AIX:#define __SIZEOF_DOUBLE__ 8
 // PPC64-AIX:#define __SIZEOF_FLOAT__ 4
+// PPC64-AIX:#define __SIZEOF_INT128__ 16
 // PPC64-AIX:#define __SIZEOF_INT__ 4
 // PPC64-AIX:#define __SIZEOF_LONG_DOUBLE__ 8
 // PPC64-AIX:#define __SIZEOF_LONG_LONG__ 8
Index: clang/test/Driver/types.c
===
--- clang/test/Driver/types.c
+++ clang/test/Driver/types.c
@@ -12,8 +12,8 @@
 // RUN: not %clang -c --target=powerpc-ibm-aix -fsyntax-only %s \
 // RUN: 2>&1 | FileCheck %s
 
-// RUN: not %clang -c --target=powerpc64-ibm-aix -fsyntax-only %s \
-// RUN: 2>&1 | FileCheck %s
+// RUN: %clang -c --target=powerpc64-ibm-aix -fsyntax-only %s \
+// RUN: 2>&1
 
 void a() {
   __int128_t s;
Index: clang/test/CodeGenCXX/debug-info-enum-i128.cpp
===
--- clang/test/CodeGenCXX/debug-info-enum-i128.cpp
+++ clang/test/CodeGenCXX/debug-info-enum-i128.cpp

[clang-tools-extra] 0c14e27 - [clangd] Revert unwanted change from D108194

2021-10-05 Thread Kirill Bobyrev via cfe-commits

Author: Kirill Bobyrev
Date: 2021-10-05T18:44:43+02:00
New Revision: 0c14e279c7294cb354e803ba5f2557425fee7c59

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

LOG: [clangd] Revert unwanted change from D108194

Added: 


Modified: 
clang-tools-extra/clangd/ParsedAST.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/ParsedAST.cpp 
b/clang-tools-extra/clangd/ParsedAST.cpp
index 53bd01b1fddf..5a3d909eb929 100644
--- a/clang-tools-extra/clangd/ParsedAST.cpp
+++ b/clang-tools-extra/clangd/ParsedAST.cpp
@@ -18,7 +18,6 @@
 #include "FeatureModule.h"
 #include "Headers.h"
 #include "HeuristicResolver.h"
-#include "IncludeCleaner.h"
 #include "IncludeFixer.h"
 #include "Preamble.h"
 #include "SourceCode.h"



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


[PATCH] D110625: [analyzer] canonicalize special case of structure/pointer deref

2021-10-05 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers planned changes to this revision.
vabridgers added a comment.

I'm refactoring the code change a bit. I'll push another update soon. Thanks 
for the comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110625

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


[PATCH] D111115: [OPENMP] Fix assert of "Unable to find base lambda address" from adjustMemberOfForLambdaCaptures.

2021-10-05 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 updated this revision to Diff 377288.
jyu2 added a comment.

Thanks Alexey's review.  This patch is address Alexe's comments by adding new 
field LambdasMap.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D15

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/test/OpenMP/nvptx_lambda_pointer_capturing.cpp

Index: clang/test/OpenMP/nvptx_lambda_pointer_capturing.cpp
===
--- clang/test/OpenMP/nvptx_lambda_pointer_capturing.cpp
+++ clang/test/OpenMP/nvptx_lambda_pointer_capturing.cpp
@@ -24,6 +24,32 @@
   }
 }
 
+template 
+void omp_loop_ref(int start, int end, F& body) {
+#pragma omp target teams distribute parallel for map(to: body)
+  for (int i = start; i < end; ++i) {
+body(i);
+  }
+  int *p;
+  const auto &body_ref = [=](int i) {p[i]=0;};
+  #pragma omp target map(to: body_ref)
+  body_ref(10);
+}
+
+template 
+struct C {
+  static void xoo(const FTy& f) {
+int x = 10;
+#pragma omp target map(to:f)
+  f(x);
+  }
+};
+
+template 
+void zoo(const FTy &functor) {
+  C::xoo(functor);
+}
+
 // CHECK: define {{.*}}[[MAIN:@.+]](
 int main()
 {
@@ -32,6 +58,7 @@
   auto body = [=](int i){
 p[i] = q[i];
   };
+  zoo([=](int i){p[i] = 0;});
 
 #pragma omp target teams distribute parallel for
   for (int i = 0; i < 100; ++i) {
@@ -82,6 +109,7 @@
 
 
   omp_loop(0,100,body);
+  omp_loop_ref(0,100,body);
 }
 
 // CHECK: [[BASE_PTRS:%.+]] = alloca [5 x i8*]{{.+}}
@@ -122,4 +150,34 @@
 // CHECK: [[PTRS_GEP:%.+]] = getelementptr {{.+}} [5 x {{.+}}*], [5 x {{.+}}*]* [[PTRS]], {{.+}} 0, {{.+}} 0
 // CHECK: {{%.+}} = call{{.+}} @__tgt_target_teams_mapper(%struct.ident_t* @{{.+}}, {{.+}}, {{.+}}, {{.+}}, i8** [[BASES_GEP]], i8** [[PTRS_GEP]], i[[PTRSZ]]* getelementptr inbounds ([5 x i{{.+}}], [5 x i{{.+}}]* [[SIZES_TEMPLATE]], i{{.+}} 0, i{{.+}} 0), i64* getelementptr inbounds ([5 x i64], [5 x i64]* [[TYPES_TEMPLATE]], i{{.+}} 0, i{{.+}} 0), i8** null, i8** null, {{.+}}, {{.+}})
 
+// CHECK: define internal void @{{.+}}omp_loop_ref{{.+}}(
+// CHECK: [[BODY:%body.addr]] = alloca %class.anon*
+// CHECK: [[TMP:%tmp]] = alloca %class.anon*
+// CHECK: [[BODY_REF:%body_ref]] = alloca %class.anon.1*
+// CHECK: [[REF_TMP:%ref.tmp]] = alloca %class.anon.1
+// CHECK: [[TMP8:%tmp.+]] = alloca %class.anon.1*
+// CHECK: [[L0:%.+]] = load %class.anon*, %class.anon** [[BODY]]
+// CHECK: store %class.anon* [[L0]], %class.anon** [[TMP]]
+// CHECK: [[L5:%.+]] = load %class.anon*, %class.anon** [[TMP]]
+// CHECK-NOT [[L6:%.+]] = load %class.anon*, %class.anon** [[TMP]]
+// CHECK-NOT [[L7:%.+]] = load %class.anon*, %class.anon** [[TMP]]
+// CHECK: store %class.anon.1* [[REF_TMP]], %class.anon.1** [[BODY_REF]]
+// CHECK:[[L47:%.+]] =  load %class.anon.1*, %class.anon.1** [[BODY_REF]]
+// CHECK: store %class.anon.1* [[L47]], %class.anon.1** [[TMP8]]
+// CHECK: [[L48:%.+]] = load %class.anon.1*, %class.anon.1** [[TMP8]]
+// CHECK-NOT: [[L49:%.+]] = load %class.anon.1*, %class.anon.1** [[TMP8]]
+// CHECK-NOT: [[L50:%.+]] = load %class.anon.1*, %class.anon.1** [[TMP8]]
+// CHECK: ret void
+
+// CHECK: define internal void @{{.+}}xoo{{.+}}(
+// CHECK: [[FADDR:%f.addr]] = alloca %class.anon.0*
+// CHECK: [[L0:%.+]] = load %class.anon.0*, %class.anon.0** [[FADDR]]
+// CHECK: store %class.anon.0* [[L0]], %class.anon.0** [[TMP:%tmp]]
+// CHECK: [[L1:%.+]] = load %class.anon.0*, %class.anon.0** [[TMP]]
+// CHECK-NOT: %4 = load %class.anon.0*, %class.anon.0** [[TMP]]
+// CHECK-NOT: %5 = load %class.anon.0*, %class.anon.0** [[TMP]]
+// CHECK: [[L4:%.+]] = getelementptr inbounds %class.anon.0, %class.anon.0* [[L1]], i32 0, i32 0
+// CHECK: [[L5:%.+]] = load i{{.*}}*, i{{.*}}** [[L4]]
+// CHECK: ret void
+
 #endif
Index: clang/lib/CodeGen/CGOpenMPRuntime.cpp
===
--- clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -7481,6 +7481,9 @@
   SmallVector>
   DevPointersMap;
 
+  /// Map between lambda declarations and their map type.
+  llvm::DenseMap LambdasMap;
+
   llvm::Value *getExprTypeSize(const Expr *E) const {
 QualType ExprTy = E->getType().getCanonicalType();
 
@@ -8442,6 +8445,17 @@
   return MappableExprsHandler::OMP_MAP_PRIVATE |
  MappableExprsHandler::OMP_MAP_TO;
 }
+auto I = LambdasMap.find(Cap.getCapturedVar()->getCanonicalDecl());
+if (I != LambdasMap.end()) {
+  // for map(to: lambda): using user specified map type.
+  ArrayRef MapModifiers;
+  ArrayRef MotionModifiers;
+  return getMapTypeBits(
+  I->getSecond(), MapModifiers, MotionModifiers, false,
+  /*AddPtrFlag=*/false,
+  /*AddIsTargetParamFlag=*/false,
+  /*isNonContiguous=*/false);
+}
 return MappableExprsHandler::OMP_MAP_TO |
MappableExprsHandler::OMP_MAP_FROM;
   }
@@ -8906,6 +8920,21 @@
 for (co

[PATCH] D111115: [OPENMP] Fix assert of "Unable to find base lambda address" from adjustMemberOfForLambdaCaptures.

2021-10-05 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/lib/CodeGen/CGOpenMPRuntime.cpp:8451-8454
+  ArrayRef MapModifiers;
+  ArrayRef MotionModifiers;
+  return getMapTypeBits(
+  I->getSecond(), MapModifiers, MotionModifiers, false,

No need to create empty ArrayRefs, just pass `llvm::None` instead.



Comment at: clang/lib/CodeGen/CGOpenMPRuntime.cpp:8923-8937
+// Extract map information.
+for (const auto *C : Dir.getClausesOfKind()) {
+  if (C->getMapType() != OMPC_MAP_to)
+continue;
+  for (auto L : C->component_lists()) {
+const ValueDecl *VD = std::get<0>(L);
+const auto *RD = VD ? VD->getType()

What if we have `to(lambda)` in data motion directive? What shall we do if 
there mapping modifiers? Not sure we shall ignore them.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D15

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


[clang] c7104e5 - [Sema] Allow comparisons between different ms ptr size address space types.

2021-10-05 Thread Amy Huang via cfe-commits

Author: Amy Huang
Date: 2021-10-05T10:56:29-07:00
New Revision: c7104e506619b551ee7ab888a040114f260e8cb5

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

LOG: [Sema] Allow comparisons between different ms ptr size address space types.

We're currently using address spaces to implement __ptr32/__ptr64 attributes;
this patch fixes a bug where clang doesn't allow types with different pointer
size attributes to be compared.

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

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

Added: 
clang/test/Sema/MicrosoftExtensions.cpp

Modified: 
clang/lib/Sema/SemaExprCXX.cpp
clang/test/CodeGen/ms-mixed-ptr-sizes.c

Removed: 




diff  --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 07d27aaf7bdc..1b4c49d7880b 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -6674,8 +6674,15 @@ QualType Sema::FindCompositePointerType(SourceLocation 
Loc,
   } else if (Steps.size() == 1) {
 bool MaybeQ1 = Q1.isAddressSpaceSupersetOf(Q2);
 bool MaybeQ2 = Q2.isAddressSpaceSupersetOf(Q1);
-if (MaybeQ1 == MaybeQ2)
-  return QualType(); // No unique best address space.
+if (MaybeQ1 == MaybeQ2) {
+  // Exception for ptr size address spaces. Should be able to choose
+  // either address space during comparison.
+  if (isPtrSizeAddressSpace(Q1.getAddressSpace()) ||
+  isPtrSizeAddressSpace(Q2.getAddressSpace()))
+MaybeQ1 = true;
+  else
+return QualType(); // No unique best address space.
+}
 Quals.setAddressSpace(MaybeQ1 ? Q1.getAddressSpace()
   : Q2.getAddressSpace());
   } else {

diff  --git a/clang/test/CodeGen/ms-mixed-ptr-sizes.c 
b/clang/test/CodeGen/ms-mixed-ptr-sizes.c
index 08e4a5f81cff..ececa42a4c4d 100644
--- a/clang/test/CodeGen/ms-mixed-ptr-sizes.c
+++ b/clang/test/CodeGen/ms-mixed-ptr-sizes.c
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -triple x86_64-windows-msvc -fms-extensions -emit-llvm -O2 
< %s | FileCheck %s --check-prefix=X64
-// RUN: %clang_cc1 -triple i386-pc-win32 -fms-extensions -emit-llvm -O2 < %s | 
FileCheck %s --check-prefix=X86
+// RUN: %clang_cc1 -triple x86_64-windows-msvc -fms-extensions -emit-llvm -O2 
< %s | FileCheck %s --check-prefixes=X64,ALL
+// RUN: %clang_cc1 -triple i386-pc-win32 -fms-extensions -emit-llvm -O2 < %s | 
FileCheck %s --check-prefixes=X86,ALL
 
 struct Foo {
   int * __ptr32 p32;
@@ -47,3 +47,39 @@ void test_other(struct Foo *f, 
__attribute__((address_space(10))) int *i) {
   f->p32 = (int * __ptr32)i;
   use_foo(f);
 }
+
+int test_compare1(int *__ptr32 __uptr i, int *__ptr64 j) {
+  // ALL-LABEL: define dso_local i32 @test_compare1
+  // X64: %{{.+}} = addrspacecast i32* %j to i32 addrspace(271)*
+  // X64: %cmp = icmp eq i32 addrspace(271)* %{{.+}}, %i
+  // X86: %{{.+}} = addrspacecast i32 addrspace(272)* %j to i32 addrspace(271)*
+  // X86: %cmp = icmp eq i32 addrspace(271)* %{{.+}}, %i
+  return (i == j);
+}
+
+int test_compare2(int *__ptr32 __sptr i, int *__ptr64 j) {
+  // ALL-LABEL: define dso_local i32 @test_compare2
+  // X64: %{{.+}} = addrspacecast i32* %j to i32 addrspace(270)*
+  // X64: %cmp = icmp eq i32 addrspace(270)* %{{.+}}, %i
+  // X86: %{{.+}} = addrspacecast i32 addrspace(272)* %j to i32*
+  // X86: %cmp = icmp eq i32* %{{.+}}, %i
+  return (i == j);
+}
+
+int test_compare3(int *__ptr32 __uptr i, int *__ptr64 j) {
+  // ALL-LABEL: define dso_local i32 @test_compare3
+  // X64: %{{.+}} = addrspacecast i32 addrspace(271)* %i to i32*
+  // X64: %cmp = icmp eq i32* %{{.+}}, %j
+  // X86: %{{.+}} = addrspacecast i32 addrspace(271)* %i to i32 addrspace(272)*
+  // X86: %cmp = icmp eq i32 addrspace(272)* %{{.+}}, %j
+  return (j == i);
+}
+
+int test_compare4(int *__ptr32 __sptr i, int *__ptr64 j) {
+  // ALL-LABEL: define dso_local i32 @test_compare4
+  // X64: %{{.+}} = addrspacecast i32 addrspace(270)* %i to i32*
+  // X64: %cmp = icmp eq i32* %{{.+}}, %j
+  // X86: %{{.+}} = addrspacecast i32* %i to i32 addrspace(272)*
+  // X86: %cmp = icmp eq i32 addrspace(272)* %{{.+}}, %j
+  return (j == i);
+}

diff  --git a/clang/test/Sema/MicrosoftExtensions.cpp 
b/clang/test/Sema/MicrosoftExtensions.cpp
new file mode 100644
index ..cb9ad2048633
--- /dev/null
+++ b/clang/test/Sema/MicrosoftExtensions.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wmicrosoft -verify 
-fms-extensions
+// RUN: %clang_cc1 -triple x86_64-windows %s -fsyntax-only -Wmicrosoft -verify 
-fms-extensions
+// expected-no-diagnostics
+
+// Check that __ptr32/__ptr64 can be compared.
+int test_ptr_comparison(int *__ptr32 __uptr p32u, int *__ptr32 __sptr p3

[PATCH] D110670: [Sema] Allow comparisons between different ms ptr size address space types.

2021-10-05 Thread Amy Huang via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc7104e506619: [Sema] Allow comparisons between different ms 
ptr size address space types. (authored by akhuang).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110670

Files:
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/CodeGen/ms-mixed-ptr-sizes.c
  clang/test/Sema/MicrosoftExtensions.cpp


Index: clang/test/Sema/MicrosoftExtensions.cpp
===
--- /dev/null
+++ clang/test/Sema/MicrosoftExtensions.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wmicrosoft -verify 
-fms-extensions
+// RUN: %clang_cc1 -triple x86_64-windows %s -fsyntax-only -Wmicrosoft -verify 
-fms-extensions
+// expected-no-diagnostics
+
+// Check that __ptr32/__ptr64 can be compared.
+int test_ptr_comparison(int *__ptr32 __uptr p32u, int *__ptr32 __sptr p32s,
+int *__ptr64 p64) {
+  return (p32u == p32s) +
+ (p32u == p64) +
+ (p32s == p64);
+}
Index: clang/test/CodeGen/ms-mixed-ptr-sizes.c
===
--- clang/test/CodeGen/ms-mixed-ptr-sizes.c
+++ clang/test/CodeGen/ms-mixed-ptr-sizes.c
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -triple x86_64-windows-msvc -fms-extensions -emit-llvm -O2 
< %s | FileCheck %s --check-prefix=X64
-// RUN: %clang_cc1 -triple i386-pc-win32 -fms-extensions -emit-llvm -O2 < %s | 
FileCheck %s --check-prefix=X86
+// RUN: %clang_cc1 -triple x86_64-windows-msvc -fms-extensions -emit-llvm -O2 
< %s | FileCheck %s --check-prefixes=X64,ALL
+// RUN: %clang_cc1 -triple i386-pc-win32 -fms-extensions -emit-llvm -O2 < %s | 
FileCheck %s --check-prefixes=X86,ALL
 
 struct Foo {
   int * __ptr32 p32;
@@ -47,3 +47,39 @@
   f->p32 = (int * __ptr32)i;
   use_foo(f);
 }
+
+int test_compare1(int *__ptr32 __uptr i, int *__ptr64 j) {
+  // ALL-LABEL: define dso_local i32 @test_compare1
+  // X64: %{{.+}} = addrspacecast i32* %j to i32 addrspace(271)*
+  // X64: %cmp = icmp eq i32 addrspace(271)* %{{.+}}, %i
+  // X86: %{{.+}} = addrspacecast i32 addrspace(272)* %j to i32 addrspace(271)*
+  // X86: %cmp = icmp eq i32 addrspace(271)* %{{.+}}, %i
+  return (i == j);
+}
+
+int test_compare2(int *__ptr32 __sptr i, int *__ptr64 j) {
+  // ALL-LABEL: define dso_local i32 @test_compare2
+  // X64: %{{.+}} = addrspacecast i32* %j to i32 addrspace(270)*
+  // X64: %cmp = icmp eq i32 addrspace(270)* %{{.+}}, %i
+  // X86: %{{.+}} = addrspacecast i32 addrspace(272)* %j to i32*
+  // X86: %cmp = icmp eq i32* %{{.+}}, %i
+  return (i == j);
+}
+
+int test_compare3(int *__ptr32 __uptr i, int *__ptr64 j) {
+  // ALL-LABEL: define dso_local i32 @test_compare3
+  // X64: %{{.+}} = addrspacecast i32 addrspace(271)* %i to i32*
+  // X64: %cmp = icmp eq i32* %{{.+}}, %j
+  // X86: %{{.+}} = addrspacecast i32 addrspace(271)* %i to i32 addrspace(272)*
+  // X86: %cmp = icmp eq i32 addrspace(272)* %{{.+}}, %j
+  return (j == i);
+}
+
+int test_compare4(int *__ptr32 __sptr i, int *__ptr64 j) {
+  // ALL-LABEL: define dso_local i32 @test_compare4
+  // X64: %{{.+}} = addrspacecast i32 addrspace(270)* %i to i32*
+  // X64: %cmp = icmp eq i32* %{{.+}}, %j
+  // X86: %{{.+}} = addrspacecast i32* %i to i32 addrspace(272)*
+  // X86: %cmp = icmp eq i32 addrspace(272)* %{{.+}}, %j
+  return (j == i);
+}
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -6674,8 +6674,15 @@
   } else if (Steps.size() == 1) {
 bool MaybeQ1 = Q1.isAddressSpaceSupersetOf(Q2);
 bool MaybeQ2 = Q2.isAddressSpaceSupersetOf(Q1);
-if (MaybeQ1 == MaybeQ2)
-  return QualType(); // No unique best address space.
+if (MaybeQ1 == MaybeQ2) {
+  // Exception for ptr size address spaces. Should be able to choose
+  // either address space during comparison.
+  if (isPtrSizeAddressSpace(Q1.getAddressSpace()) ||
+  isPtrSizeAddressSpace(Q2.getAddressSpace()))
+MaybeQ1 = true;
+  else
+return QualType(); // No unique best address space.
+}
 Quals.setAddressSpace(MaybeQ1 ? Q1.getAddressSpace()
   : Q2.getAddressSpace());
   } else {


Index: clang/test/Sema/MicrosoftExtensions.cpp
===
--- /dev/null
+++ clang/test/Sema/MicrosoftExtensions.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wmicrosoft -verify -fms-extensions
+// RUN: %clang_cc1 -triple x86_64-windows %s -fsyntax-only -Wmicrosoft -verify -fms-extensions
+// expected-no-diagnostics
+
+// Check that __ptr32/__ptr64 can be compared.
+int test_ptr_comparison(int *__ptr32 __uptr p32u, int *__ptr32 __sptr p3

[PATCH] D111169: [AIX] Disable tests failing due to assert on DWARF object writing

2021-10-05 Thread Jake Egan via Phabricator via cfe-commits
Jake-Egan created this revision.
Herald added subscribers: ormris, pengfei, arphaman, steven_wu, hiraditya, 
emaste.
Jake-Egan requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, MaskRay.
Herald added projects: clang, LLVM.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D69

Files:
  clang/test/ClangScanDeps/modules-full-by-mod-name.cpp
  clang/test/ClangScanDeps/modules-pch.c
  clang/test/CodeGenCXX/crash.cpp
  clang/test/Modules/DebugInfoSubmodules.c
  clang/test/Modules/ModuleDebugInfo.m
  clang/test/Modules/lsv-debuginfo.cpp
  clang/test/PCH/debug-info-pch-container-path.c
  clang/test/PCH/debug-info-pch-path.c
  llvm/test/CodeGen/X86/dbg-distringtype-uint.ll
  llvm/test/DebugInfo/Generic/2010-04-06-NestedFnDbgInfo.ll
  llvm/test/DebugInfo/Generic/2010-05-10-MultipleCU.ll
  llvm/test/DebugInfo/Generic/DICommonBlock.ll
  llvm/test/DebugInfo/Generic/PR20038.ll
  llvm/test/DebugInfo/Generic/constant-pointers.ll
  llvm/test/DebugInfo/Generic/containing-type-extension.ll
  llvm/test/DebugInfo/Generic/cross-cu-inlining.ll
  llvm/test/DebugInfo/Generic/cross-cu-linkonce-distinct.ll
  llvm/test/DebugInfo/Generic/cross-cu-linkonce.ll
  llvm/test/DebugInfo/Generic/cu-range-hole.ll
  llvm/test/DebugInfo/Generic/cu-ranges.ll
  llvm/test/DebugInfo/Generic/dead-argument-order.ll
  llvm/test/DebugInfo/Generic/debug-info-enum.ll
  llvm/test/DebugInfo/Generic/debug-info-qualifiers.ll
  llvm/test/DebugInfo/Generic/debug-label-inline.ll
  llvm/test/DebugInfo/Generic/debug-label.ll
  llvm/test/DebugInfo/Generic/def-line.ll
  llvm/test/DebugInfo/Generic/discriminated-union.ll
  llvm/test/DebugInfo/Generic/discriminator.ll
  llvm/test/DebugInfo/Generic/disubrange_vla.ll
  llvm/test/DebugInfo/Generic/disubrange_vla_no_dbgvalue.ll
  llvm/test/DebugInfo/Generic/dwarf-public-names.ll
  llvm/test/DebugInfo/Generic/empty.ll
  llvm/test/DebugInfo/Generic/enum-types.ll
  llvm/test/DebugInfo/Generic/enum.ll
  llvm/test/DebugInfo/Generic/fortran-subprogram-attr.ll
  llvm/test/DebugInfo/Generic/global.ll
  llvm/test/DebugInfo/Generic/gmlt.test
  llvm/test/DebugInfo/Generic/gmlt_profiling.ll
  llvm/test/DebugInfo/Generic/imported-name-inlined.ll
  llvm/test/DebugInfo/Generic/incorrect-variable-debugloc.ll
  llvm/test/DebugInfo/Generic/incorrect-variable-debugloc1.ll
  llvm/test/DebugInfo/Generic/inline-scopes.ll
  llvm/test/DebugInfo/Generic/inlined-arguments.ll
  llvm/test/DebugInfo/Generic/inlined-strings.ll
  llvm/test/DebugInfo/Generic/line-table-addrx.ll
  llvm/test/DebugInfo/Generic/linkage-name-abstract.ll
  llvm/test/DebugInfo/Generic/lto-comp-dir.ll
  llvm/test/DebugInfo/Generic/mainsubprogram.ll
  llvm/test/DebugInfo/Generic/member-order.ll
  llvm/test/DebugInfo/Generic/member-pointers.ll
  llvm/test/DebugInfo/Generic/missing-abstract-variable.ll
  llvm/test/DebugInfo/Generic/namespace.ll
  llvm/test/DebugInfo/Generic/namespace_function_definition.ll
  llvm/test/DebugInfo/Generic/namespace_inline_function_definition.ll
  llvm/test/DebugInfo/Generic/no-empty-child-vars.ll
  llvm/test/DebugInfo/Generic/noscopes.ll
  llvm/test/DebugInfo/Generic/pass-by-value.ll
  llvm/test/DebugInfo/Generic/ptrsize.ll
  llvm/test/DebugInfo/Generic/recursive_inlining.ll
  llvm/test/DebugInfo/Generic/restrict.ll
  llvm/test/DebugInfo/Generic/skeletoncu.ll
  llvm/test/DebugInfo/Generic/sugared-constants.ll
  llvm/test/DebugInfo/Generic/template-recursive-void.ll
  llvm/test/DebugInfo/Generic/thrownTypes.ll
  llvm/test/DebugInfo/Generic/tu-composite.ll
  llvm/test/DebugInfo/Generic/tu-member-pointer.ll
  llvm/test/DebugInfo/Generic/two-cus-from-same-file.ll
  llvm/test/DebugInfo/Generic/typedef.ll
  llvm/test/DebugInfo/Generic/unconditional-branch.ll
  llvm/test/DebugInfo/Generic/univariant-discriminated-union.ll
  llvm/test/DebugInfo/Generic/varargs.ll
  llvm/test/DebugInfo/Generic/version.ll
  llvm/test/DebugInfo/Generic/virtual-index.ll
  llvm/test/DebugInfo/X86/dwarfdump-generic_subrange.ll
  llvm/test/DebugInfo/X86/dwarfdump-generic_subrange_const.ll
  llvm/test/DebugInfo/X86/dwarfdump-generic_subrange_count.ll
  llvm/test/DebugInfo/X86/dwarfdump-rankConst.ll
  llvm/test/DebugInfo/X86/dwarfdump-rankExp.ll
  llvm/test/DebugInfo/X86/dwarfdump-signed_const.ll
  llvm/test/DebugInfo/X86/global-constants.ll
  llvm/test/DebugInfo/X86/objc_direct.ll
  llvm/test/DebugInfo/cross-cu-scope.ll
  llvm/test/DebugInfo/dwo.ll
  llvm/test/DebugInfo/skeletoncu.ll
  llvm/test/Linker/subprogram-linkonce-weak.ll
  llvm/test/Linker/type-unique-odr-a.ll
  llvm/test/Linker/type-unique-simple-a.ll
  llvm/test/Linker/type-unique-simple2-a.ll
  llvm/test/Linker/type-unique-simple2.ll
  llvm/test/Linker/type-unique-type-array-a.ll
  llvm/test/MC/ELF/cfi-version.ll
  llvm/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp
  llvm/unittests/DebugInfo/DWARF/DWARFDebugLineTest.cpp
  llvm/unittests/DebugInfo/DWARF/DWARFDieManualExtractTest.cpp
  llvm/unittests/Passes/PluginsTest.cpp

Index: llvm/unittests/Passes/PluginsTest

[PATCH] D107049: [clang-repl] Re-implement clang-interpreter as a test case.

2021-10-05 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev updated this revision to Diff 377303.
v.g.vassilev added a comment.

Upload the newest version of this patch. It has several improvements that came 
from various bot failures. We just need to outline the `llvm::consumeError` to 
be able to call it from exceptions land and fix the last known failure on 
hexagon.


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

https://reviews.llvm.org/D107049

Files:
  clang/docs/ClangFormattedStatus.rst
  clang/examples/CMakeLists.txt
  clang/examples/clang-interpreter/CMakeLists.txt
  clang/examples/clang-interpreter/README.txt
  clang/examples/clang-interpreter/Test.cxx
  clang/include/clang/Interpreter/Interpreter.h
  clang/lib/Interpreter/IncrementalExecutor.cpp
  clang/lib/Interpreter/IncrementalExecutor.h
  clang/lib/Interpreter/Interpreter.cpp
  clang/test/CMakeLists.txt
  clang/test/Misc/interpreter.c
  clang/test/lit.cfg.py
  clang/unittests/Interpreter/CMakeLists.txt
  clang/unittests/Interpreter/ExceptionTests/CMakeLists.txt
  clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp
  clang/unittests/Interpreter/InterpreterTest.cpp

Index: clang/unittests/Interpreter/InterpreterTest.cpp
===
--- clang/unittests/Interpreter/InterpreterTest.cpp
+++ clang/unittests/Interpreter/InterpreterTest.cpp
@@ -17,8 +17,6 @@
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/TextDiagnosticPrinter.h"
 
-#include "llvm/ADT/ArrayRef.h"
-
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
Index: clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp
===
--- /dev/null
+++ clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp
@@ -0,0 +1,131 @@
+//===- unittests/Interpreter/InterpreterExceptionTest.cpp -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// Unit tests for Clang's Interpreter library.
+//
+//===--===//
+
+#include "clang/Interpreter/Interpreter.h"
+
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/DeclGroup.h"
+#include "clang/Basic/TargetInfo.h"
+#include "clang/Basic/Version.h"
+#include "clang/Config/config.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Frontend/TextDiagnosticPrinter.h"
+
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ExecutionEngine/Orc/LLJIT.h"
+#include "llvm/Support/ManagedStatic.h"
+#include "llvm/Support/TargetSelect.h"
+
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+using namespace clang;
+
+namespace {
+using Args = std::vector;
+static std::unique_ptr
+createInterpreter(const Args &ExtraArgs = {},
+  DiagnosticConsumer *Client = nullptr) {
+  Args ClangArgs = {"-Xclang", "-emit-llvm-only"};
+  ClangArgs.insert(ClangArgs.end(), ExtraArgs.begin(), ExtraArgs.end());
+  auto CI = cantFail(clang::IncrementalCompilerBuilder::create(ClangArgs));
+  if (Client)
+CI->getDiagnostics().setClient(Client, /*ShouldOwnClient=*/false);
+  return cantFail(clang::Interpreter::create(std::move(CI)));
+}
+
+TEST(InterpreterTest, CatchException) {
+  llvm::InitializeNativeTarget();
+  llvm::InitializeNativeTargetAsmPrinter();
+
+  {
+auto J = llvm::orc::LLJITBuilder().create();
+if (!J) {
+  // The platform does not support JITs.
+  // We can't use llvm::consumeError as it needs typeinfo for ErrorInfoBase.
+  auto E = J.takeError();
+  (void)E;
+  return;
+}
+  }
+
+#define Stringify(s) Stringifyx(s)
+#define Stringifyx(s) #s
+
+  // We define a custom exception to avoid #include-ing the  header
+  // which would require this test to know about the libstdc++ location.
+  // its own header file.
+#define CUSTOM_EXCEPTION   \
+  struct custom_exception {\
+custom_exception(const char *Msg) : Message(Msg) {}\
+const char *Message;   \
+  };
+
+  CUSTOM_EXCEPTION;
+
+  std::string ExceptionCode = Stringify(CUSTOM_EXCEPTION);
+  ExceptionCode +=
+  R"(
+extern "C" int printf(const char*, ...);
+static void ThrowerAnError(const char* Name) {
+  throw custom_exception(Name);
+}
+
+extern "C" int throw_exception() {
+  try {
+ThrowerAnError("In JIT");
+  } catch (const custom_exception& E) {
+printf("Caught: '%s'\n", E.Message);
+  } catch (...) {
+printf("Unknown exception\n");
+  }
+  ThrowerAnError("From JIT");
+  return 0;
+}
+)";
+  std::unique_ptr Interp = createInterpreter();
+  //

[PATCH] D110436: Add %n format specifier warning

2021-10-05 Thread Jayson Yan via Phabricator via cfe-commits
Jaysonyan added a comment.

Since no discussion came out of the RFC I'll leave the warning under the 
`-Wformat-n-specifier` flag under `-Wformat`
unless there's other ideas brought up. Would appreciate any reviews at this 
points! :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110436

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


[PATCH] D111169: [AIX] Disable tests failing due to assert on DWARF object writing

2021-10-05 Thread Jake Egan via Phabricator via cfe-commits
Jake-Egan updated this revision to Diff 377306.
Jake-Egan added a comment.

Updated to preserve blank lines.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69

Files:
  clang/test/ClangScanDeps/modules-full-by-mod-name.cpp
  clang/test/ClangScanDeps/modules-pch.c
  clang/test/CodeGenCXX/crash.cpp
  clang/test/Modules/DebugInfoSubmodules.c
  clang/test/Modules/ModuleDebugInfo.m
  clang/test/Modules/lsv-debuginfo.cpp
  clang/test/PCH/debug-info-pch-container-path.c
  clang/test/PCH/debug-info-pch-path.c
  llvm/test/CodeGen/X86/dbg-distringtype-uint.ll
  llvm/test/DebugInfo/Generic/2010-04-06-NestedFnDbgInfo.ll
  llvm/test/DebugInfo/Generic/2010-05-10-MultipleCU.ll
  llvm/test/DebugInfo/Generic/DICommonBlock.ll
  llvm/test/DebugInfo/Generic/PR20038.ll
  llvm/test/DebugInfo/Generic/constant-pointers.ll
  llvm/test/DebugInfo/Generic/containing-type-extension.ll
  llvm/test/DebugInfo/Generic/cross-cu-inlining.ll
  llvm/test/DebugInfo/Generic/cross-cu-linkonce-distinct.ll
  llvm/test/DebugInfo/Generic/cross-cu-linkonce.ll
  llvm/test/DebugInfo/Generic/cu-range-hole.ll
  llvm/test/DebugInfo/Generic/cu-ranges.ll
  llvm/test/DebugInfo/Generic/dead-argument-order.ll
  llvm/test/DebugInfo/Generic/debug-info-enum.ll
  llvm/test/DebugInfo/Generic/debug-info-qualifiers.ll
  llvm/test/DebugInfo/Generic/debug-label-inline.ll
  llvm/test/DebugInfo/Generic/debug-label.ll
  llvm/test/DebugInfo/Generic/def-line.ll
  llvm/test/DebugInfo/Generic/discriminated-union.ll
  llvm/test/DebugInfo/Generic/discriminator.ll
  llvm/test/DebugInfo/Generic/disubrange_vla.ll
  llvm/test/DebugInfo/Generic/disubrange_vla_no_dbgvalue.ll
  llvm/test/DebugInfo/Generic/dwarf-public-names.ll
  llvm/test/DebugInfo/Generic/empty.ll
  llvm/test/DebugInfo/Generic/enum-types.ll
  llvm/test/DebugInfo/Generic/enum.ll
  llvm/test/DebugInfo/Generic/fortran-subprogram-attr.ll
  llvm/test/DebugInfo/Generic/global.ll
  llvm/test/DebugInfo/Generic/gmlt.test
  llvm/test/DebugInfo/Generic/gmlt_profiling.ll
  llvm/test/DebugInfo/Generic/imported-name-inlined.ll
  llvm/test/DebugInfo/Generic/incorrect-variable-debugloc.ll
  llvm/test/DebugInfo/Generic/incorrect-variable-debugloc1.ll
  llvm/test/DebugInfo/Generic/inline-scopes.ll
  llvm/test/DebugInfo/Generic/inlined-arguments.ll
  llvm/test/DebugInfo/Generic/inlined-strings.ll
  llvm/test/DebugInfo/Generic/line-table-addrx.ll
  llvm/test/DebugInfo/Generic/linkage-name-abstract.ll
  llvm/test/DebugInfo/Generic/lto-comp-dir.ll
  llvm/test/DebugInfo/Generic/mainsubprogram.ll
  llvm/test/DebugInfo/Generic/member-order.ll
  llvm/test/DebugInfo/Generic/member-pointers.ll
  llvm/test/DebugInfo/Generic/missing-abstract-variable.ll
  llvm/test/DebugInfo/Generic/namespace.ll
  llvm/test/DebugInfo/Generic/namespace_function_definition.ll
  llvm/test/DebugInfo/Generic/namespace_inline_function_definition.ll
  llvm/test/DebugInfo/Generic/no-empty-child-vars.ll
  llvm/test/DebugInfo/Generic/noscopes.ll
  llvm/test/DebugInfo/Generic/pass-by-value.ll
  llvm/test/DebugInfo/Generic/ptrsize.ll
  llvm/test/DebugInfo/Generic/recursive_inlining.ll
  llvm/test/DebugInfo/Generic/restrict.ll
  llvm/test/DebugInfo/Generic/skeletoncu.ll
  llvm/test/DebugInfo/Generic/sugared-constants.ll
  llvm/test/DebugInfo/Generic/template-recursive-void.ll
  llvm/test/DebugInfo/Generic/thrownTypes.ll
  llvm/test/DebugInfo/Generic/tu-composite.ll
  llvm/test/DebugInfo/Generic/tu-member-pointer.ll
  llvm/test/DebugInfo/Generic/two-cus-from-same-file.ll
  llvm/test/DebugInfo/Generic/typedef.ll
  llvm/test/DebugInfo/Generic/unconditional-branch.ll
  llvm/test/DebugInfo/Generic/univariant-discriminated-union.ll
  llvm/test/DebugInfo/Generic/varargs.ll
  llvm/test/DebugInfo/Generic/version.ll
  llvm/test/DebugInfo/Generic/virtual-index.ll
  llvm/test/DebugInfo/X86/dwarfdump-generic_subrange.ll
  llvm/test/DebugInfo/X86/dwarfdump-generic_subrange_const.ll
  llvm/test/DebugInfo/X86/dwarfdump-generic_subrange_count.ll
  llvm/test/DebugInfo/X86/dwarfdump-rankConst.ll
  llvm/test/DebugInfo/X86/dwarfdump-rankExp.ll
  llvm/test/DebugInfo/X86/dwarfdump-signed_const.ll
  llvm/test/DebugInfo/X86/global-constants.ll
  llvm/test/DebugInfo/X86/objc_direct.ll
  llvm/test/DebugInfo/cross-cu-scope.ll
  llvm/test/DebugInfo/dwo.ll
  llvm/test/DebugInfo/skeletoncu.ll
  llvm/test/Linker/subprogram-linkonce-weak.ll
  llvm/test/Linker/type-unique-odr-a.ll
  llvm/test/Linker/type-unique-simple-a.ll
  llvm/test/Linker/type-unique-simple2-a.ll
  llvm/test/Linker/type-unique-simple2.ll
  llvm/test/Linker/type-unique-type-array-a.ll
  llvm/test/MC/ELF/cfi-version.ll
  llvm/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp
  llvm/unittests/DebugInfo/DWARF/DWARFDebugLineTest.cpp
  llvm/unittests/DebugInfo/DWARF/DWARFDieManualExtractTest.cpp
  llvm/unittests/Passes/PluginsTest.cpp

Index: llvm/unittests/Passes/PluginsTest.cpp
===
--- llvm/u

[PATCH] D107049: [clang-repl] Re-implement clang-interpreter as a test case.

2021-10-05 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev updated this revision to Diff 377307.
v.g.vassilev marked 5 inline comments as done.
v.g.vassilev added a comment.

address comments


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

https://reviews.llvm.org/D107049

Files:
  clang/examples/CMakeLists.txt
  clang/examples/clang-interpreter/CMakeLists.txt
  clang/examples/clang-interpreter/README.txt
  clang/examples/clang-interpreter/Test.cxx
  clang/include/clang/Interpreter/Interpreter.h
  clang/lib/Interpreter/IncrementalExecutor.cpp
  clang/lib/Interpreter/IncrementalExecutor.h
  clang/lib/Interpreter/Interpreter.cpp
  clang/test/CMakeLists.txt
  clang/test/Misc/interpreter.c
  clang/test/lit.cfg.py
  clang/unittests/Interpreter/CMakeLists.txt
  clang/unittests/Interpreter/ExceptionTests/CMakeLists.txt
  clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp
  clang/unittests/Interpreter/InterpreterTest.cpp

Index: clang/unittests/Interpreter/InterpreterTest.cpp
===
--- clang/unittests/Interpreter/InterpreterTest.cpp
+++ clang/unittests/Interpreter/InterpreterTest.cpp
@@ -17,8 +17,6 @@
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/TextDiagnosticPrinter.h"
 
-#include "llvm/ADT/ArrayRef.h"
-
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
Index: clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp
===
--- /dev/null
+++ clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp
@@ -0,0 +1,131 @@
+//===- unittests/Interpreter/InterpreterExceptionTest.cpp -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// Unit tests for Clang's Interpreter library.
+//
+//===--===//
+
+#include "clang/Interpreter/Interpreter.h"
+
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/DeclGroup.h"
+#include "clang/Basic/TargetInfo.h"
+#include "clang/Basic/Version.h"
+#include "clang/Config/config.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Frontend/TextDiagnosticPrinter.h"
+
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ExecutionEngine/Orc/LLJIT.h"
+#include "llvm/Support/ManagedStatic.h"
+#include "llvm/Support/TargetSelect.h"
+
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+using namespace clang;
+
+namespace {
+using Args = std::vector;
+static std::unique_ptr
+createInterpreter(const Args &ExtraArgs = {},
+  DiagnosticConsumer *Client = nullptr) {
+  Args ClangArgs = {"-Xclang", "-emit-llvm-only"};
+  ClangArgs.insert(ClangArgs.end(), ExtraArgs.begin(), ExtraArgs.end());
+  auto CI = cantFail(clang::IncrementalCompilerBuilder::create(ClangArgs));
+  if (Client)
+CI->getDiagnostics().setClient(Client, /*ShouldOwnClient=*/false);
+  return cantFail(clang::Interpreter::create(std::move(CI)));
+}
+
+TEST(InterpreterTest, CatchException) {
+  llvm::InitializeNativeTarget();
+  llvm::InitializeNativeTargetAsmPrinter();
+
+  {
+auto J = llvm::orc::LLJITBuilder().create();
+if (!J) {
+  // The platform does not support JITs.
+  // We can't use llvm::consumeError as it needs typeinfo for ErrorInfoBase.
+  auto E = J.takeError();
+  (void)E;
+  return;
+}
+  }
+
+#define Stringify(s) Stringifyx(s)
+#define Stringifyx(s) #s
+
+  // We define a custom exception to avoid #include-ing the  header
+  // which would require this test to know about the libstdc++ location.
+  // its own header file.
+#define CUSTOM_EXCEPTION   \
+  struct custom_exception {\
+custom_exception(const char *Msg) : Message(Msg) {}\
+const char *Message;   \
+  };
+
+  CUSTOM_EXCEPTION;
+
+  std::string ExceptionCode = Stringify(CUSTOM_EXCEPTION);
+  ExceptionCode +=
+  R"(
+extern "C" int printf(const char*, ...);
+static void ThrowerAnError(const char* Name) {
+  throw custom_exception(Name);
+}
+
+extern "C" int throw_exception() {
+  try {
+ThrowerAnError("To be caught in JIT");
+  } catch (const custom_exception& E) {
+printf("Caught: '%s'\n", E.Message);
+  } catch (...) {
+printf("Unknown exception\n");
+  }
+  ThrowerAnError("To be caught in binary");
+  return 0;
+}
+)";
+  std::unique_ptr Interp = createInterpreter();
+  // FIXME: Re-enable the excluded target triples.
+  const clang::CompilerInstance *CI = Interp->getCompilerInstance();
+  const llvm::Triple &Triple = CI->getASTContext().getTargetInfo().getTri

[PATCH] D107049: [clang-repl] Re-implement clang-interpreter as a test case.

2021-10-05 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev added inline comments.



Comment at: 
clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp:102
+  } catch (...) {
+printf("Unknown exception\n");
+  }

karies wrote:
> How is that provoking a test failure? What about `exit(1)` or whatever works 
> for gtest?
we use EXPECT_ANY_THROW and expect output on the stdout. I guess that line is 
not reachable.



Comment at: 
clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp:104
+  }
+  ThrowerAnError("From JIT");
+  return 0;

karies wrote:
> To me, the wording difference between "In JIT" and "From JIT" doesn't signal 
> anything. Maybe "the first could be "To be caught in JIT" and the second "To 
> be caught in binary"?
The intent was to show that we can move the clang-interpreter example with 
relatively small amount of changes to the libInterpreter interfaces. we have 
changed that goal significantly and maybe we should also change the strings, 
too.


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

https://reviews.llvm.org/D107049

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


[PATCH] D110625: [analyzer] canonicalize special case of structure/pointer deref

2021-10-05 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers updated this revision to Diff 377309.
vabridgers added a comment.
This revision is now accepted and ready to land.

Refactor compare a little bit


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110625

Files:
  clang/lib/StaticAnalyzer/Core/Store.cpp
  clang/test/Analysis/ptr-arith.c


Index: clang/test/Analysis/ptr-arith.c
===
--- clang/test/Analysis/ptr-arith.c
+++ clang/test/Analysis/ptr-arith.c
@@ -2,6 +2,7 @@
 // RUN: %clang_analyze_cc1 
-analyzer-checker=alpha.core.FixedAddr,alpha.core.PointerArithm,alpha.core.PointerSub,debug.ExprInspection
 -analyzer-store=region -Wno-pointer-to-int-cast -verify -triple 
i686-apple-darwin9 -Wno-tautological-pointer-compare -analyzer-config 
eagerly-assume=false %s
 
 void clang_analyzer_eval(int);
+void clang_analyzer_dump(int);
 
 void f1() {
   int a[10];
@@ -330,3 +331,59 @@
   simd_float2 x = {0, 1};
   return x[1]; // no-warning
 }
+
+struct s {
+  int v;
+};
+
+// These three expressions should produce the same sym vals.
+void struct_pointer_canon(struct s *ps) {
+  struct s ss = *ps;
+  clang_analyzer_dump((*ps).v);
+  // expected-warning-re@-1{{reg_${{[[:digit:]]+}}}.v>}}
+  clang_analyzer_dump(ps[0].v);
+  // expected-warning-re@-1{{reg_${{[[:digit:]]+}}}.v>}}
+  clang_analyzer_dump(ps->v);
+  // expected-warning-re@-1{{reg_${{[[:digit:]]+}}}.v>}}
+  clang_analyzer_eval((*ps).v == ps[0].v); // expected-warning{{TRUE}}
+  clang_analyzer_eval((*ps).v == ps->v);   // expected-warning{{TRUE}}
+  clang_analyzer_eval(ps[0].v == ps->v);   // expected-warning{{TRUE}}
+}
+
+void struct_pointer_canon_bidim(struct s **ps) {
+  struct s ss = **ps;
+  clang_analyzer_eval(&(ps[0][0].v) == &((*ps)->v)); // 
expected-warning{{TRUE}}
+}
+
+typedef struct s T1;
+typedef struct s T2;
+void struct_pointer_canon_typedef(T1 *ps) {
+  T2 ss = *ps;
+  clang_analyzer_dump((*ps).v);
+  // expected-warning-re@-1{{reg_${{[[:digit:]]+}}}.v>}}
+  clang_analyzer_dump(ps[0].v);
+  // expected-warning-re@-1{{reg_${{[[:digit:]]+}}}.v>}}
+  clang_analyzer_dump(ps->v);
+  // expected-warning-re@-1{{reg_${{[[:digit:]]+}}}.v>}}
+  clang_analyzer_eval((*ps).v == ps[0].v); // expected-warning{{TRUE}}
+  clang_analyzer_eval((*ps).v == ps->v);   // expected-warning{{TRUE}}
+  clang_analyzer_eval(ps[0].v == ps->v);   // expected-warning{{TRUE}}
+}
+
+void struct_pointer_canon_bidim_typedef(T1 **ps) {
+  T2 ss = **ps;
+  clang_analyzer_eval(&(ps[0][0].v) == &((*ps)->v)); // 
expected-warning{{TRUE}}
+}
+
+void struct_pointer_canon_const(const struct s *ps) {
+  struct s ss = *ps;
+  clang_analyzer_dump((*ps).v);
+  // expected-warning-re@-1{{reg_${{[[:digit:]]+}}}.v>}}
+  clang_analyzer_dump(ps[0].v);
+  // expected-warning-re@-1{{reg_${{[[:digit:]]+}}}.v>}}
+  clang_analyzer_dump(ps->v);
+  // expected-warning-re@-1{{reg_${{[[:digit:]]+}}}.v>}}
+  clang_analyzer_eval((*ps).v == ps[0].v); // expected-warning{{TRUE}}
+  clang_analyzer_eval((*ps).v == ps->v);   // expected-warning{{TRUE}}
+  clang_analyzer_eval(ps[0].v == ps->v);   // expected-warning{{TRUE}}
+}
Index: clang/lib/StaticAnalyzer/Core/Store.cpp
===
--- clang/lib/StaticAnalyzer/Core/Store.cpp
+++ clang/lib/StaticAnalyzer/Core/Store.cpp
@@ -442,6 +442,19 @@
 
 SVal StoreManager::getLValueElement(QualType elementType, NonLoc Offset,
 SVal Base) {
+
+  // Special case, if index is 0, return the same type as if
+  // this was not an array dereference.
+  if (Offset.isZeroConstant()) {
+QualType BT = Base.getType(this->Ctx);
+if (!BT.isNull() && !elementType.isNull()) {
+  QualType PointeeTy = BT->getPointeeType();
+  if (!PointeeTy.isNull() &&
+  PointeeTy.getCanonicalType() == elementType.getCanonicalType())
+return Base;
+}
+  }
+
   // If the base is an unknown or undefined value, just return it back.
   // FIXME: For absolute pointer addresses, we just return that value back as
   //  well, although in reality we should return the offset added to that


Index: clang/test/Analysis/ptr-arith.c
===
--- clang/test/Analysis/ptr-arith.c
+++ clang/test/Analysis/ptr-arith.c
@@ -2,6 +2,7 @@
 // RUN: %clang_analyze_cc1 -analyzer-checker=alpha.core.FixedAddr,alpha.core.PointerArithm,alpha.core.PointerSub,debug.ExprInspection -analyzer-store=region -Wno-pointer-to-int-cast -verify -triple i686-apple-darwin9 -Wno-tautological-pointer-compare -analyzer-config eagerly-assume=false %s
 
 void clang_analyzer_eval(int);
+void clang_analyzer_dump(int);
 
 void f1() {
   int a[10];
@@ -330,3 +331,59 @@
   simd_float2 x = {0, 1};
   return x[1]; // no-warning
 }
+
+struct s {
+  int v;
+};
+
+// These three expressions should produce the same sym vals.
+void struct_pointer_canon(struct s *ps) {
+  struct 

[PATCH] D110781: [CUDA] Make sure is included with original __THROW defined.

2021-10-05 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

@jdoerfert: Ping.  I think you're the best match for reviewing the code related 
to interaction between CUDA and the system include files, even if this 
particular header does not have much to do with OpenMP.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110781

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


[PATCH] D108482: [Clang] Fix instantiation of OpaqueValueExprs (Bug #45964)

2021-10-05 Thread Jason Rice via Phabricator via cfe-commits
ricejasonf updated this revision to Diff 377316.
ricejasonf marked 2 inline comments as done.
ricejasonf added a comment.

Fix up c++ version in test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108482

Files:
  clang/lib/Sema/TreeTransform.h
  clang/test/CodeGenCXX/pr45964-decomp-transform.cpp


Index: clang/test/CodeGenCXX/pr45964-decomp-transform.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/pr45964-decomp-transform.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -std=c++17 -triple x86_64-linux-gnu -emit-llvm -o - %s | 
FileCheck %s
+
+int a[1];
+// CHECK: @a = global [1 x i32] zeroinitializer
+template 
+void test_transform() {
+  auto [b] = a;
+}
+void (*d)(){test_transform<0>};
+// CHECK-LABEL: define {{.*}} @_Z14test_transformILi0EEvv
+// CHECK:   [[ENTRY:.*]]:
+// CHECK-NEXT:  [[ARR:%.*]] = alloca [1 x i32]
+// CHECK-NEXT:  [[BEGIN:%.*]] = getelementptr inbounds [1 x i32], [1 x i32]* 
[[ARR]], i64 0, i64 0
+// CHECK-NEXT:  br label %[[BODY:.*]]
+// CHECK-EMPTY:
+// CHECK-NEXT:  [[BODY]]:
+// CHECK-NEXT:  [[CUR:%.*]] = phi i64 [ 0, %[[ENTRY]] ], [ [[NEXT:%.*]], 
%[[BODY]] ]
+// CHECK-NEXT:  [[DEST:%.*]] = getelementptr inbounds i32, i32* [[BEGIN]], i64 
[[CUR]]
+// CHECK-NEXT:  [[SRC:%.*]] = getelementptr inbounds [1 x i32], [1 x i32]* @a, 
i64 0, i64 [[CUR]]
+// CHECK-NEXT:  [[X:%.*]] = load i32, i32* [[SRC]]
+// CHECK-NEXT:  store i32 [[X]], i32* [[DEST]]
+// CHECK-NEXT:  [[NEXT]] = add nuw i64 [[CUR]], 1
+// CHECK-NEXT:  [[EQ:%.*]] = icmp eq i64 [[NEXT]], 1
+// CHECK-NEXT:  br i1 [[EQ]], label %[[FIN:.*]], label %[[BODY]]
+// CHECK-EMPTY:
+// CHECK-NEXT:  [[FIN]]:
+// CHECK-NEXT:  ret void
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -3840,8 +3840,10 @@
   if (auto *FE = dyn_cast(Init))
 Init = FE->getSubExpr();
 
-  if (auto *AIL = dyn_cast(Init))
-Init = AIL->getCommonExpr();
+  if (auto *AIL = dyn_cast(Init)) {
+auto *OVE = cast(AIL->getCommonExpr());
+Init = OVE->getSourceExpr();
+  }
 
   if (MaterializeTemporaryExpr *MTE = dyn_cast(Init))
 Init = MTE->getSubExpr();


Index: clang/test/CodeGenCXX/pr45964-decomp-transform.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/pr45964-decomp-transform.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -std=c++17 -triple x86_64-linux-gnu -emit-llvm -o - %s | FileCheck %s
+
+int a[1];
+// CHECK: @a = global [1 x i32] zeroinitializer
+template 
+void test_transform() {
+  auto [b] = a;
+}
+void (*d)(){test_transform<0>};
+// CHECK-LABEL: define {{.*}} @_Z14test_transformILi0EEvv
+// CHECK:   [[ENTRY:.*]]:
+// CHECK-NEXT:  [[ARR:%.*]] = alloca [1 x i32]
+// CHECK-NEXT:  [[BEGIN:%.*]] = getelementptr inbounds [1 x i32], [1 x i32]* [[ARR]], i64 0, i64 0
+// CHECK-NEXT:  br label %[[BODY:.*]]
+// CHECK-EMPTY:
+// CHECK-NEXT:  [[BODY]]:
+// CHECK-NEXT:  [[CUR:%.*]] = phi i64 [ 0, %[[ENTRY]] ], [ [[NEXT:%.*]], %[[BODY]] ]
+// CHECK-NEXT:  [[DEST:%.*]] = getelementptr inbounds i32, i32* [[BEGIN]], i64 [[CUR]]
+// CHECK-NEXT:  [[SRC:%.*]] = getelementptr inbounds [1 x i32], [1 x i32]* @a, i64 0, i64 [[CUR]]
+// CHECK-NEXT:  [[X:%.*]] = load i32, i32* [[SRC]]
+// CHECK-NEXT:  store i32 [[X]], i32* [[DEST]]
+// CHECK-NEXT:  [[NEXT]] = add nuw i64 [[CUR]], 1
+// CHECK-NEXT:  [[EQ:%.*]] = icmp eq i64 [[NEXT]], 1
+// CHECK-NEXT:  br i1 [[EQ]], label %[[FIN:.*]], label %[[BODY]]
+// CHECK-EMPTY:
+// CHECK-NEXT:  [[FIN]]:
+// CHECK-NEXT:  ret void
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -3840,8 +3840,10 @@
   if (auto *FE = dyn_cast(Init))
 Init = FE->getSubExpr();
 
-  if (auto *AIL = dyn_cast(Init))
-Init = AIL->getCommonExpr();
+  if (auto *AIL = dyn_cast(Init)) {
+auto *OVE = cast(AIL->getCommonExpr());
+Init = OVE->getSourceExpr();
+  }
 
   if (MaterializeTemporaryExpr *MTE = dyn_cast(Init))
 Init = MTE->getSubExpr();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D111109: AddGlobalAnnotations for function with or without function body.

2021-10-05 Thread Xiang Li via Phabricator via cfe-commits
python3kgae updated this revision to Diff 377323.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D09

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGen/annotations-global.c
  clang/test/CodeGenCXX/attr-annotate.cpp

Index: clang/test/CodeGenCXX/attr-annotate.cpp
===
--- clang/test/CodeGenCXX/attr-annotate.cpp
+++ clang/test/CodeGenCXX/attr-annotate.cpp
@@ -1,11 +1,16 @@
 // RUN: %clang_cc1 %s -S -emit-llvm -triple x86_64-unknown-linux-gnu -o - | FileCheck %s
 
+//CHECK: @[[STR:.*]] = private unnamed_addr constant [5 x i8] c"test\00", section "llvm.metadata"
 //CHECK: @[[STR1:.*]] = private unnamed_addr constant [{{.*}} x i8] c"{{.*}}attr-annotate.cpp\00", section "llvm.metadata"
 //CHECK: @[[STR2:.*]] = private unnamed_addr constant [4 x i8] c"abc\00", align 1
-//CHECK: @[[STR:.*]] = private unnamed_addr constant [5 x i8] c"test\00", section "llvm.metadata"
 //CHECK: @[[ARGS:.*]] = private unnamed_addr constant { i32, i8*, i32 } { i32 9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @[[STR2:.*]], i32 0, i32 0), i32 8 }, section "llvm.metadata"
 //CHECK: @[[ARGS2:.*]] = private unnamed_addr constant { %struct.Struct } { %struct.Struct { i32* getelementptr inbounds ([2 x i32], [2 x i32]* @_ZN1AIjLj9EE2SVE, i32 0, i32 0), i32* bitcast (i8* getelementptr (i8, i8* bitcast ([2 x i32]* @_ZN1AIjLj9EE2SVE to i8*), i64 4) to i32*) } }, section "llvm.metadata"
-//CHECK: @llvm.global.annotations = appending global [2 x { i8*, i8*, i8*, i32, i8* }] [{ i8*, i8*, i8*, i32, i8* } { i8* bitcast (void (%struct.A*)* @_ZN1AIjLj9EE4testILi8EEEvv to i8*), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @[[STR:.*]], i32 0, i32 0), i8* getelementptr inbounds ([{{.*}} x i8], [{{.*}} x i8]* @[[STR1:.*]], i32 0, i32 0), i32 {{.*}}, i8* bitcast ({ i32, i8*, i32 }* @[[ARGS:.*]] to i8*) }, { i8*, i8*, i8*, i32, i8* } { i8* bitcast (void (%struct.A*)* @_ZN1AIjLj9EE5test2Ev to i8*), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([{{.*}} x i8], [{{.*}} x i8]* @.str.1, i32 0, i32 0), i32 24, i8* bitcast ({ %struct.Struct }* @[[ARGS2]] to i8*) }]
+//CHECK: @[[VANN0:.*]] = private unnamed_addr constant [8 x i8] c"v_ann_0\00", section "llvm.metadata"
+//CHECK: @[[B_ARG_IMM_7:.*]] = private unnamed_addr constant { i8*, i32, i32 } { i8* getelementptr inbounds ([4 x i8], [4 x i8]* @[[STR2]], i32 0, i32 0), i32 90, i32 7 }, section "llvm.metadata"
+//CHECK: @[[VANN1:.*]] = private unnamed_addr constant [8 x i8] c"v_ann_1\00", section "llvm.metadata"
+//CHECK: @[[VAAN1_ARG_IMM9:.*]] = private unnamed_addr constant { i32 } { i32 9 }, section "llvm.metadata"
+//CHECK: @[[B_ARG_IMM_NEG1:.*]] = private unnamed_addr constant { i8*, i32, i64 } { i8* getelementptr inbounds ([4 x i8], [4 x i8]* @[[STR2]], i32 0, i32 0), i32 90, i64 -1 }, section "llvm.metadata"
+//CHECK: @llvm.global.annotations = appending global [2 x { i8*, i8*, i8*, i32, i8* }] [{ i8*, i8*, i8*, i32, i8* } { i8* bitcast (void (%struct.A*)* @_ZN1AIjLj9EE4testILi8EEEvv to i8*), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @[[STR]], i32 0, i32 0), i8* getelementptr inbounds ([{{.*}} x i8], [{{.*}} x i8]* @[[STR1]], i32 0, i32 0), i32 {{.*}}, i8* bitcast ({ i32, i8*, i32 }* @[[ARGS]] to i8*) }, { i8*, i8*, i8*, i32, i8* } { i8* bitcast (void (%struct.A*)* @_ZN1AIjLj9EE5test2Ev to i8*), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @[[STR]], i32 0, i32 0), i8* getelementptr inbounds ([{{.*}} x i8], [{{.*}} x i8]* @[[STR1]], i32 0, i32 0), i32 {{.*}}, i8* bitcast ({ %struct.Struct }* @[[ARGS2]] to i8*) }]
 
 constexpr const char* str() {
   return "abc";
@@ -52,17 +57,17 @@
 // CHECK-NEXT:[[TMP0:%.*]] = load i32, i32* [[ARGC_ADDR]], align 4
 // CHECK-NEXT:[[V:%.*]] = getelementptr inbounds %"struct.B::foo", %"struct.B::foo"* [[F]], i32 0, i32 0
 // CHECK-NEXT:[[TMP1:%.*]] = bitcast i32* [[V]] to i8*
-// CHECK-NEXT:[[TMP2:%.*]] = call i8* @llvm.ptr.annotation.p0i8(i8* [[TMP1]], i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([{{.*}} x i8], [{{.*}} x i8]* @.str.1, i32 0, i32 0), i32 {{.*}}, i8* bitcast ({ i8*, i32, i32 }* @.args to i8*))
+// CHECK-NEXT:[[TMP2:%.*]] = call i8* @llvm.ptr.annotation.p0i8(i8* [[TMP1]], i8* getelementptr inbounds ([8 x i8], [8 x i8]* @[[VANN0]], i32 0, i32 0), i8* getelementptr inbounds ([{{.*}} x i8], [{{.*}} x i8]* @.str.1, i32 0, i32 0), i32 {{.*}}, i8* bitcast ({ i8*, i32, i32 }* @[[B_ARG_IMM_7]] to i8*))
 // CHECK-NEXT:[[TMP3:%.*]] = bitcast i8* [[TMP2]] to i32*
 // CHECK-NEXT:[[TMP4:%.*]] = bitcast i32* [[TMP3]] to i8*
-// CHECK-NEXT:[[TMP5:%.*]] = call i8* @llvm.ptr.annotation.p0i8(i8* [[TMP4]], i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([{{.*}} x i8], [{{.*}} x i8]* @.str.1, i32 0, i32 0), i32 {{

[PATCH] D111115: [OPENMP] Fix assert of "Unable to find base lambda address" from adjustMemberOfForLambdaCaptures.

2021-10-05 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 added inline comments.



Comment at: clang/lib/CodeGen/CGOpenMPRuntime.cpp:8923-8937
+// Extract map information.
+for (const auto *C : Dir.getClausesOfKind()) {
+  if (C->getMapType() != OMPC_MAP_to)
+continue;
+  for (auto L : C->component_lists()) {
+const ValueDecl *VD = std::get<0>(L);
+const auto *RD = VD ? VD->getType()

ABataev wrote:
> What if we have `to(lambda)` in data motion directive? What shall we do if 
> there mapping modifiers? Not sure we shall ignore them.
to(lambda) is not isOpenMPTargetExecutionDirective.  I don't see 
generateInfoForLambdaCaptures and adjustMemberOfForLambdaCaptures functions  
get called in that part.  Those two functions only called in emitTargetCall. 
 So I don't think we need that.
What do you think? 
Thanks.
Jennifer


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D15

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


[PATCH] D110436: Add %n format specifier warning

2021-10-05 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

The trouble with this diagnostic is that it throws the baby out with the 
bathwater. It is possible to securely use `%n`, so we can't have this warning 
be on by default because it will have too high of a false positive rate. 
However, we typically don't introduce new warning flags that are off by default 
because experience has shown that users typically do not enable those.

Can we reduce the diagnostic's scope to only the problematic uses of `%n` 
instead of all uses? If all uses is the desired diagnostic, have you considered 
adding it to the `bugprone` module in clang-tidy instead?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110436

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


[PATCH] D111175: [Clang] Extend init-statement to allow alias-declaration

2021-10-05 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin created this revision.
Herald added a subscriber: jeroen.dobbelaere.
cor3ntin requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Implement P2360R0 in C++23 mode and as an extension in older
languages mode.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75

Files:
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/include/clang/Parse/Parser.h
  clang/lib/Parse/ParseExprCXX.cpp
  clang/lib/Parse/ParseStmt.cpp
  clang/lib/Parse/ParseTentative.cpp
  clang/test/Parser/cxx2b-init-statement.cpp
  clang/test/SemaCXX/cxx2b-init-statement.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1365,7 +1365,7 @@
 
   Extend init-statement to allow alias-declaration
   https://wg21.link/P2360R0";>P2360R0
-  No
+  Clang 14
 
 
 
Index: clang/test/SemaCXX/cxx2b-init-statement.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/cxx2b-init-statement.cpp
@@ -0,0 +1,28 @@
+// RUN: %clang_cc1 -verify -std=c++2b -Wall -Wshadow %s
+
+void f() {
+
+for (using foo = int;true;) {} //expected-warning {{unused type alias 'foo'}}
+
+switch(using foo = int; 0) { //expected-warning {{unused type alias 'foo'}}
+case 0: break;
+}
+
+if(using foo = int; false) {} // expected-warning {{unused type alias 'foo'}}
+
+int x; // expected-warning {{unused variable 'x'}}
+if(using x = int; true) {}  // expected-warning {{unused type alias 'x'}}
+
+using y = int; // expected-warning {{unused type alias 'y'}} \
+   // expected-note 2{{previous declaration is here}}
+
+if(using y = double; true) {}  // expected-warning {{unused type alias 'y'}} \
+   // expected-warning {{declaration shadows a type alias in function 'f'}}
+
+for(using y = double; true;) { // expected-warning {{declaration shadows a type alias in function 'f'}}
+y foo = 0;
+(void)foo;
+constexpr y var = 0;
+static_assert(var == 0);
+}
+}
Index: clang/test/Parser/cxx2b-init-statement.cpp
===
--- /dev/null
+++ clang/test/Parser/cxx2b-init-statement.cpp
@@ -0,0 +1,34 @@
+// RUN: %clang_cc1 -fsyntax-only -verify=expected -std=c++2b -Wall %s
+// RUN: %clang_cc1 -fsyntax-only -verify=expected,expected-cxx20 -std=c++20 -Wall %s
+
+namespace ns {
+int i;
+enum class e {};
+}
+void f() {
+
+for (using foo = int;true;); //expected-cxx20-warning {{alias declaration in init statements is a C++2b extension}}
+
+switch(using foo = int; 0) { //expected-cxx20-warning {{alias declaration in init statements is a C++2b extension}}
+case 0: break;
+}
+
+if(using foo = int; false) {} //expected-cxx20-warning {{alias declaration in init statements is a C++2b extension}}
+
+
+if (using enum ns::e; false){}  // expected-error {{expected alias declaration after using in init statement}} \
+// expected-cxx20-warning {{alias declaration in init statements is a C++2b extension}}
+
+
+for (using ns::i; true;);  // expected-error {{expected alias declaration after using in init statement}} \
+   // expected-cxx20-warning {{alias declaration in init statements is a C++2b extension}}
+
+if (using ns::i; false){}  // expected-error {{expected alias declaration after using in init statement}} \
+   // expected-cxx20-warning {{alias declaration in init statements is a C++2b extension}}
+
+switch(using ns::i; 0) {   // expected-error {{expected alias declaration after using in init statement}} \
+   // expected-cxx20-warning {{alias declaration in init statements is a C++2b extension}}
+case 0: break;
+}
+
+}
Index: clang/lib/Parse/ParseTentative.cpp
===
--- clang/lib/Parse/ParseTentative.cpp
+++ clang/lib/Parse/ParseTentative.cpp
@@ -483,7 +483,9 @@
   ConditionDeclarationOrInitStatementState State(*this, CanBeInitStatement,
  CanBeForRangeDecl);
 
-  if (State.update(isCXXDeclarationSpecifier()))
+  if (CanBeInitStatement && Tok.is(tok::kw_using)) {
+return ConditionOrInitStatement::InitStmtDecl;
+  } else if (State.update(isCXXDeclarationSpecifier()))
 return State.result();
 
   // It might be a declaration; we need tentative parsing.
Index: clang/lib/Parse/ParseStmt.cpp
===
--- clang/lib/Parse/ParseStmt.cpp
+++ clang/lib/Parse/ParseStmt.cpp
@@ -1823,6 +1823,7 @@
 /// [C++] for-init-statement:
 /// [C++]   expression-statement
 /// [C++]   simple-declara

[PATCH] D110436: Add %n format specifier warning

2021-10-05 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:9230
+def warn_printf_n_specifier : Warning<
+  "usage of '%%n' can lead to unsafe writing to memory">, 
InGroup;
 def warn_printf_data_arg_not_used : Warning<

FWIW, I don't understand why this is "unsafe" either. The problem with `%n` is 
not that it might be used //intentionally//; the problem is that it opens up an 
attack vector for //unintentional// (malicious) use. The programmer writes 
`printf(buf, args...)` where `buf` is under the attacker's control (for example 
a debug-log format string supplied in a config file), and then the //attacker// 
configures something like `"%n"` instead of `"%s%d"` (so the debug-logging 
routine ends up poking data instead of peeking it). This vulnerable 
`printf(buf, ...)` is exactly what `-Wformat-security` warns about.
I am not aware of any vulnerability from //intentional// use of `%n`. At best, 
one could argue that there's a moral hazard: we might like to remove 
`%n`-support from our libc's printf, but we can't do that as long as there's 
any code out there in the wild that relies on intentional use of `%n`. 
Therefore, this is essentially a "deprecation warning" — but for a feature that 
AFAIK has never been deprecated, neither by C nor C++! (Am I wrong? Has someone 
officially deprecated `%n`?)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110436

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


[PATCH] D111115: [OPENMP] Fix assert of "Unable to find base lambda address" from adjustMemberOfForLambdaCaptures.

2021-10-05 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/lib/CodeGen/CGOpenMPRuntime.cpp:8923-8937
+// Extract map information.
+for (const auto *C : Dir.getClausesOfKind()) {
+  if (C->getMapType() != OMPC_MAP_to)
+continue;
+  for (auto L : C->component_lists()) {
+const ValueDecl *VD = std::get<0>(L);
+const auto *RD = VD ? VD->getType()

jyu2 wrote:
> ABataev wrote:
> > What if we have `to(lambda)` in data motion directive? What shall we do if 
> > there mapping modifiers? Not sure we shall ignore them.
> to(lambda) is not isOpenMPTargetExecutionDirective.  I don't see 
> generateInfoForLambdaCaptures and adjustMemberOfForLambdaCaptures functions  
> get called in that part.  Those two functions only called in emitTargetCall. 
>  So I don't think we need that.
> What do you think? 
> Thanks.
> Jennifer
Ok, let's skip it for now but still need to keep in mind to fix/implement it in 
the future.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D15

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


[PATCH] D110436: Add %n format specifier warning

2021-10-05 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:9230
+def warn_printf_n_specifier : Warning<
+  "usage of '%%n' can lead to unsafe writing to memory">, 
InGroup;
 def warn_printf_data_arg_not_used : Warning<

Quuxplusone wrote:
> FWIW, I don't understand why this is "unsafe" either. The problem with `%n` 
> is not that it might be used //intentionally//; the problem is that it opens 
> up an attack vector for //unintentional// (malicious) use. The programmer 
> writes `printf(buf, args...)` where `buf` is under the attacker's control 
> (for example a debug-log format string supplied in a config file), and then 
> the //attacker// configures something like `"%n"` instead of `"%s%d"` (so the 
> debug-logging routine ends up poking data instead of peeking it). This 
> vulnerable `printf(buf, ...)` is exactly what `-Wformat-security` warns about.
> I am not aware of any vulnerability from //intentional// use of `%n`. At 
> best, one could argue that there's a moral hazard: we might like to remove 
> `%n`-support from our libc's printf, but we can't do that as long as there's 
> any code out there in the wild that relies on intentional use of `%n`. 
> Therefore, this is essentially a "deprecation warning" — but for a feature 
> that AFAIK has never been deprecated, neither by C nor C++! (Am I wrong? Has 
> someone officially deprecated `%n`?)
FWIW, that's effectively how I view this as well -- it's kinda like `-Wvla` -- 
a diagnostic to say "congrats, you're using the feature!". However, unlike 
`-Wvla`, no one accidentally uses `%n` when they were expecting something else.

`%n` isn't deprecated in either C or C++.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110436

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


[PATCH] D111105: [clang] Add option to clear AST memory before running LLVM passes

2021-10-05 Thread David Blaikie via Phabricator via cfe-commits
dblaikie accepted this revision.
dblaikie added a comment.
This revision is now accepted and ready to land.

Seems like a good place to start with experimentation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D05

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


[PATCH] D109557: Adds a BreakBeforeClosingParen option

2021-10-05 Thread Guillaume Racicot via Phabricator via cfe-commits
gracicot added a comment.

In D109557#3021667 , 
@HazardyKnusperkeks wrote:

> In D109557#3021312 , 
> @MyDeveloperDay wrote:
>
>> FYI, this is a very aggressive change, I highly recommend you run this over 
>> a large code base before landing. to double check, here is one slight oddity 
>> which I cannot determine if its correct or not.
>>
>>   void foo() {
>>   if (quitelongarg != (alsolongarg - 1)) { // ABC is a very 
>> long comment
>> return;
>>   }
>>   }
>>
>> becomes
>>
>>   void foo() {
>> if (quitelongarg != (alsolongarg - 1)
>> ) { // ABC is a very long comment
>>   return;
>> }
>>   }
>>
>>
>>
>>   BasedOnStyle: LLVM
>>   BreakBeforeClosingParen: true
>>
>> That might be what you expect but I wasn't quite sure
>
> That is at least not what is covered in the tests or documentation. I would 
> think it only applies to function declarations and invocations.
> So either adapt documentation and test coverage, or fix behavior (in which 
> case the tests should be extended as well).

I'm waiting for this patch to finally use clang format in our code and we apply 
this style to all braces. This include ifs, for loops, and all control flow.

We use this style specifically in many places in our code:

  if (
 longCondition1
  or longCondition2
  or longCondition3
  ) {
  // code
  }

The you quoted would, in my mind, be formatted like this:

  void foo() {
  if (
  quitelongarg != (alsolongarg - 1)
  ) { // ABC is a very long comment
  return;
  }
  }

This is because I don't allow breaking the closing paren without breaking after 
the opening paren, but this might be only my own style.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109557

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


[PATCH] D111105: [clang] Add option to clear AST memory before running LLVM passes

2021-10-05 Thread David Blaikie via Phabricator via cfe-commits
dblaikie requested changes to this revision.
dblaikie added a subscriber: aaron.ballman.
dblaikie added a comment.
This revision now requires changes to proceed.

Oh, looking at this ab it further I do have some things to discuss.




Comment at: clang/include/clang/Driver/Options.td:5300-5302
+def clear_ast_before_backend : Flag<["-"], "clear-ast-before-backend">,
+  HelpText<"Clear the Clang AST before running backend code generation">,
+  MarshallingInfoFlag>;

I think you might have to flag this as a NonDriverOption otherwise it'd be 
accepted as a driver option, when I guess it's only intended as a CC1 option? 
(looks like lots of other options have this mistake, unfortrunately - 
@aaron.ballman )



Comment at: clang/test/Misc/clear-ast-before-backend.c:2-3
+// RUN: %clang -target x86_64-linux-gnu -c -Xclang -clear-ast-before-backend 
%s -S
+// RUN: %clang -target x86_64-linux-gnu -c -Xclang -clear-ast-before-backend 
%s -S -### 2>&1 | FileCheck %s
+// CHECK: "-clear-ast-before-backend"

This is a driver test, but not a very interesting one - it tests that -Xclang 
arguments are passed directyl to cc1, which is probably tested elsewhere 
already?

I'm not sure there's anything we could really test with the first RUN line - 
though since it's not a Driver test and doesn't need to be a Driver test - it 
should probably just test cc1 -clear-ast-before-backend directly rather than 
going through the driver+-Xclang


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D05

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


[PATCH] D111178: Fix clang postMerge logic based on System V ABI Standard

2021-10-05 Thread Vanessasaurus via Phabricator via cfe-commits
vsoch created this revision.
vsoch added reviewers: LLVM, llvm.org.
vsoch created this object with edit policy "Only User: vsoch (Vanessasaurus)".
vsoch added a project: LLVM.
Herald added a subscriber: pengfei.
vsoch requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The System V ABI standard (page 22 point 5.a 
https://raw.githubusercontent.com/dyninst/ABI-Analysis-for-Dynamic-Calls/master/callsite_parsing/docs/AMD64/x86-64-psABI-1.0.pdf)
 states that:

> If one of the classes is MEMORY, the whole argument is passed in memory

F19433717: image.png 

Implying that both classes Lo and Hi should be checked. However the clang 
matching code does not honor this request, as it only checks if Hi == Memory 
(and then updates Lo). Reading the standard (which is also included in the 
docstring) it can take a developer down a rabbit hole worrying about the lack 
of consistency. In basic testing of a struct with large values 
(https://github.com/buildsi/llvm-bug/tree/main/struct), the result I found was 
that the postMerge step would return MEMORY NOCLASS without this fix, and 
MEMORY MEMORY with it. Since if either both classes are MEMORY or one is MEMORY 
and the other NOCLASS both results in MEMORY, this would not be an ABI break 
(the resulting binaries are the same), however I cannot attest that there 
aren't other niche cases that might lead to a break. It also could be the case 
that a developer is using this function for a different use case, and then 
would get a different result. For these reasons, and possibly saving someone 
future time or angst to see a clear difference between what the standard says 
and the implementation, I am suggesting a fix to the postMerge function so that 
it properly reflects the System V ABI document to check both Lo and Hi.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D78

Files:
  clang/lib/CodeGen/TargetInfo.cpp


Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -2776,8 +2776,10 @@
   //
   // Note that clauses (b) and (c) were added in 0.98.
   //
-  if (Hi == Memory)
+  if ((Hi == Memory) || (Lo == Memory)) {
 Lo = Memory;
+Hi = Memory;
+  }
   if (Hi == X87Up && Lo != X87 && honorsRevision0_98())
 Lo = Memory;
   if (AggregateSize > 128 && (Lo != SSE || Hi != SSEUp))


Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -2776,8 +2776,10 @@
   //
   // Note that clauses (b) and (c) were added in 0.98.
   //
-  if (Hi == Memory)
+  if ((Hi == Memory) || (Lo == Memory)) {
 Lo = Memory;
+Hi = Memory;
+  }
   if (Hi == X87Up && Lo != X87 && honorsRevision0_98())
 Lo = Memory;
   if (AggregateSize > 128 && (Lo != SSE || Hi != SSEUp))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   >