[PATCH] D140292: [OpenMP] Migrate OpenMPOffloadMappingFlags from Clang CodeGen to OMPConstants

2022-12-21 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis marked 2 inline comments as done.
TIFitis added inline comments.



Comment at: llvm/include/llvm/Frontend/OpenMP/OMPConstants.h:193
-  OMP_TGT_EXEC_MODE_GENERIC | OMP_TGT_EXEC_MODE_SPMD,
-  LLVM_MARK_AS_BITMASK_ENUM(/* LargestValue */ OMP_TGT_EXEC_MODE_GENERIC_SPMD)
 };

jdoerfert wrote:
> TIFitis wrote:
> > jdoerfert wrote:
> > > TIFitis wrote:
> > > > I am not sure if this change is safe. It can be avoided by making 
> > > > `OpenMPOffloadMappingFlags` an enum class.
> > > Why do you need to change this enum at all?
> > Otherwise you'd have two declarations of LLVM_MARK_AS_BITMASK_ENUM in the 
> > same namespace which is an error ofc. 
> > 
> > This is because they are both enums which spill the declarations to the 
> > enclosing namespace, I.e. llvm::omp
> But we are using that type in binary operations w/o cast. Does this change 
> then not break existing code?
Going by the comments `LLVM_MARK_AS_BITMASK_ENUM` should be used to mark the 
largest individual enum, don't see any restrictions on it being used with 
multiple enum's in the same namespace.

`check-all` is also clean. I don't see any evidence of this being unsafe.

Changing `OpenMPOffloadMappingFlags` to enum class however, would be the safest 
thing to do but that would introduce a lot of ugly static_cast everywhere.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140292

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


[PATCH] D140018: [clang-tidy] Support std::string_view in readability-redundant-string-cstr

2022-12-21 Thread Nathan James via Phabricator via cfe-commits
njames93 accepted this revision.
njames93 added a comment.

LGTM, thank you for the patch


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140018

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


[PATCH] D86881: Make -fvisibility-inlines-hidden apply to static local variables in inline functions on Darwin

2022-12-21 Thread Stephan Bergmann via Phabricator via cfe-commits
sberg added a comment.
Herald added a project: All.

In D86881#2777808 , @arphaman wrote:

> Hey, thanks for following up on this PR. I've done some more digging and I 
> think we can remove this Darwin-specific workaround in the near future. I'm 
> hoping to provide an update in the next few weeks.

The Darwin `-fvisibility-inlines-hidden-static-local-var` hack is still present 
on Clang 16 trunk.  Any update on this?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86881

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


[clang-tools-extra] 01303f6 - [clang-tidy] Fix crash in bugprone-suspicious-realloc-usage.

2022-12-21 Thread Balázs Kéri via cfe-commits

Author: Balázs Kéri
Date: 2022-12-21T09:29:20+01:00
New Revision: 01303f6d1bba5f8640aab022469f9e9a9d66f877

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

LOG: [clang-tidy] Fix crash in bugprone-suspicious-realloc-usage.

The problem occurs if a statement is found by the checker that has a null child.
Fixes issue #59518.

Reviewed By: hokein

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/bugprone/SuspiciousReallocUsageCheck.cpp

clang-tools-extra/test/clang-tidy/checkers/bugprone/suspicious-realloc-usage.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/bugprone/SuspiciousReallocUsageCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/SuspiciousReallocUsageCheck.cpp
index bb975bc893d0d..9b78c219fc5a9 100644
--- a/clang-tools-extra/clang-tidy/bugprone/SuspiciousReallocUsageCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/SuspiciousReallocUsageCheck.cpp
@@ -95,7 +95,7 @@ class FindAssignToVarBefore
   }
   bool VisitStmt(const Stmt *S) {
 for (const Stmt *Child : S->children())
-  if (Visit(Child))
+  if (Child && Visit(Child))
 return true;
 return false;
   }

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/suspicious-realloc-usage.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/suspicious-realloc-usage.cpp
index 6e3c7f4174845..3647d1232b4ff 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/suspicious-realloc-usage.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/suspicious-realloc-usage.cpp
@@ -100,3 +100,10 @@ void warn_if_copy_exists_after(void *p) {
   // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'p' may be set to null if 
'realloc' fails, which may result in a leak of the original buffer 
[bugprone-suspicious-realloc-usage]
   void *q = p;
 }
+
+void test_null_child(void *p) {
+  for (;;)
+break;
+  p = realloc(p, 111);
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'p' may be set to null if 
'realloc' fails, which may result in a leak of the original buffer 
[bugprone-suspicious-realloc-usage]
+}



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


[PATCH] D140194: [clang-tidy] Fix crash in bugprone-suspicious-realloc-usage.

2022-12-21 Thread Balázs Kéri via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG01303f6d1bba: [clang-tidy] Fix crash in 
bugprone-suspicious-realloc-usage. (authored by balazske).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140194

Files:
  clang-tools-extra/clang-tidy/bugprone/SuspiciousReallocUsageCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone/suspicious-realloc-usage.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/bugprone/suspicious-realloc-usage.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/bugprone/suspicious-realloc-usage.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/bugprone/suspicious-realloc-usage.cpp
@@ -100,3 +100,10 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'p' may be set to null if 
'realloc' fails, which may result in a leak of the original buffer 
[bugprone-suspicious-realloc-usage]
   void *q = p;
 }
+
+void test_null_child(void *p) {
+  for (;;)
+break;
+  p = realloc(p, 111);
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'p' may be set to null if 
'realloc' fails, which may result in a leak of the original buffer 
[bugprone-suspicious-realloc-usage]
+}
Index: clang-tools-extra/clang-tidy/bugprone/SuspiciousReallocUsageCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/SuspiciousReallocUsageCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/SuspiciousReallocUsageCheck.cpp
@@ -95,7 +95,7 @@
   }
   bool VisitStmt(const Stmt *S) {
 for (const Stmt *Child : S->children())
-  if (Visit(Child))
+  if (Child && Visit(Child))
 return true;
 return false;
   }


Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/suspicious-realloc-usage.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone/suspicious-realloc-usage.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/suspicious-realloc-usage.cpp
@@ -100,3 +100,10 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'p' may be set to null if 'realloc' fails, which may result in a leak of the original buffer [bugprone-suspicious-realloc-usage]
   void *q = p;
 }
+
+void test_null_child(void *p) {
+  for (;;)
+break;
+  p = realloc(p, 111);
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'p' may be set to null if 'realloc' fails, which may result in a leak of the original buffer [bugprone-suspicious-realloc-usage]
+}
Index: clang-tools-extra/clang-tidy/bugprone/SuspiciousReallocUsageCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/SuspiciousReallocUsageCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/SuspiciousReallocUsageCheck.cpp
@@ -95,7 +95,7 @@
   }
   bool VisitStmt(const Stmt *S) {
 for (const Stmt *Child : S->children())
-  if (Visit(Child))
+  if (Child && Visit(Child))
 return true;
 return false;
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D140195: [Clang][CGDebugInfo][ObjC] Mark objc bitfields with the DIFlagBitfield flag

2022-12-21 Thread Juan Manuel Martinez Caamaño via Phabricator via cfe-commits
jmmartinez added a comment.

In D140195#4008724 , @aprantl wrote:

>> Unluckly, I wasn't able to test the combination of 
>> https://reviews.llvm.org/D96334 and this patch together. If you have some 
>> pointers about how to trigger a test job on "Green Dragon", or how to test 
>> lldb's objective-c tests on Linux I'd be happy to test.
>
> There's no way to request a test from green dragon. There is also no way to 
> test LLDB's Objective-C support on Linux, or at least I'm not aware of anyone 
> maintaining a port of LLDB to the GNUstep Objective-C runtime.
> So I tried out the patch on a Mac locally and the entire LLDB testsuite still 
> passes.

Thanks for the help in testing! Did you happen to test with 
https://reviews.llvm.org/D96334 ? If you confirm I'll "revert the revert" 
(commit 920de9c94caff0b3ac21bf637487b07cb9aea98a 
).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140195

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


[clang] 1341780 - [clang][AST] Compare UnresolvedLookupExpr in structural equivalence.

2022-12-21 Thread Balázs Kéri via cfe-commits

Author: Balázs Kéri
Date: 2022-12-21T09:58:50+01:00
New Revision: 13417808474cacc064b90726705862a650c0b28a

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

LOG: [clang][AST] Compare UnresolvedLookupExpr in structural equivalence.

Reviewed By: gamesh411

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

Added: 


Modified: 
clang/lib/AST/ASTStructuralEquivalence.cpp
clang/unittests/AST/StructuralEquivalenceTest.cpp

Removed: 




diff  --git a/clang/lib/AST/ASTStructuralEquivalence.cpp 
b/clang/lib/AST/ASTStructuralEquivalence.cpp
index e234e083813e9..46321f5ba7cf9 100644
--- a/clang/lib/AST/ASTStructuralEquivalence.cpp
+++ b/clang/lib/AST/ASTStructuralEquivalence.cpp
@@ -102,6 +102,9 @@ static bool 
IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
 static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
  const TemplateArgument &Arg1,
  const TemplateArgument &Arg2);
+static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
+ const TemplateArgumentLoc &Arg1,
+ const TemplateArgumentLoc &Arg2);
 static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
  NestedNameSpecifier *NNS1,
  NestedNameSpecifier *NNS2);
@@ -340,6 +343,30 @@ class StmtComparer {
 return true;
   }
 
+  bool IsStmtEquivalent(const OverloadExpr *E1, const OverloadExpr *E2) {
+if (!IsStructurallyEquivalent(Context, E1->getName(), E2->getName()))
+  return false;
+
+if (static_cast(E1->getQualifier()) !=
+static_cast(E2->getQualifier()))
+  return false;
+if (E1->getQualifier() &&
+!IsStructurallyEquivalent(Context, E1->getQualifier(),
+  E2->getQualifier()))
+  return false;
+
+if (E1->getNumTemplateArgs() != E2->getNumTemplateArgs())
+  return false;
+const TemplateArgumentLoc *Args1 = E1->getTemplateArgs();
+const TemplateArgumentLoc *Args2 = E2->getTemplateArgs();
+for (unsigned int ArgI = 0, ArgN = E1->getNumTemplateArgs(); ArgI < ArgN;
+ ++ArgI)
+  if (!IsStructurallyEquivalent(Context, Args1[ArgI], Args2[ArgI]))
+return false;
+
+return true;
+  }
+
   /// End point of the traversal chain.
   bool TraverseStmt(const Stmt *S1, const Stmt *S2) { return true; }
 
@@ -599,6 +626,14 @@ static bool 
IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
   return true;
 }
 
+/// Determine whether two template argument locations are equivalent.
+static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
+ const TemplateArgumentLoc &Arg1,
+ const TemplateArgumentLoc &Arg2) {
+  return IsStructurallyEquivalent(Context, Arg1.getArgument(),
+  Arg2.getArgument());
+}
+
 /// Determine structural equivalence for the common part of array
 /// types.
 static bool IsArrayStructurallyEquivalent(StructuralEquivalenceContext 
&Context,

diff  --git a/clang/unittests/AST/StructuralEquivalenceTest.cpp 
b/clang/unittests/AST/StructuralEquivalenceTest.cpp
index 3f89bcef73729..03616d7197ea8 100644
--- a/clang/unittests/AST/StructuralEquivalenceTest.cpp
+++ b/clang/unittests/AST/StructuralEquivalenceTest.cpp
@@ -2125,5 +2125,128 @@ TEST_F(StructuralEquivalenceStmtTest, 
UnaryOperatorDifferentOps) {
   EXPECT_FALSE(testStructuralMatch(t));
 }
 
+TEST_F(StructuralEquivalenceStmtTest, UnresolvedLookupDifferentName) {
+  auto t = makeStmts(
+  R"(
+  void f1(int);
+  template 
+  void f(T t) {
+f1(t);
+  }
+  void g() { f(1); }
+  )",
+  R"(
+  void f2(int);
+  template 
+  void f(T t) {
+f2(t);
+  }
+  void g() { f(1); }
+  )",
+  Lang_CXX03, unresolvedLookupExpr());
+  EXPECT_FALSE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceStmtTest, UnresolvedLookupDifferentQualifier) {
+  auto t = makeStmts(
+  R"(
+  struct X {
+static void g(int);
+static void g(char);
+  };
+
+  template 
+  void f(T t) {
+X::g(t);
+  }
+
+  void g() { f(1); }
+  )",
+  R"(
+  struct Y {
+static void g(int);
+static void g(char);
+  };
+
+  template 
+  void f(T t) {
+Y::g(t);
+  }
+
+  void g() { f(1); }
+  )",
+  Lang_CXX03, unresolvedLookupExpr());
+  EXPECT_FALSE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceStmtTest,
+   UnresolvedLookupDifferentTemplateArgument) {
+  auto t = makeStmts(
+   

[PATCH] D136848: [clang][AST] Compare UnresolvedLookupExpr in structural equivalence.

2022-12-21 Thread Balázs Kéri via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG13417808474c: [clang][AST] Compare UnresolvedLookupExpr in 
structural equivalence. (authored by balazske).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136848

Files:
  clang/lib/AST/ASTStructuralEquivalence.cpp
  clang/unittests/AST/StructuralEquivalenceTest.cpp

Index: clang/unittests/AST/StructuralEquivalenceTest.cpp
===
--- clang/unittests/AST/StructuralEquivalenceTest.cpp
+++ clang/unittests/AST/StructuralEquivalenceTest.cpp
@@ -2125,5 +2125,128 @@
   EXPECT_FALSE(testStructuralMatch(t));
 }
 
+TEST_F(StructuralEquivalenceStmtTest, UnresolvedLookupDifferentName) {
+  auto t = makeStmts(
+  R"(
+  void f1(int);
+  template 
+  void f(T t) {
+f1(t);
+  }
+  void g() { f(1); }
+  )",
+  R"(
+  void f2(int);
+  template 
+  void f(T t) {
+f2(t);
+  }
+  void g() { f(1); }
+  )",
+  Lang_CXX03, unresolvedLookupExpr());
+  EXPECT_FALSE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceStmtTest, UnresolvedLookupDifferentQualifier) {
+  auto t = makeStmts(
+  R"(
+  struct X {
+static void g(int);
+static void g(char);
+  };
+
+  template 
+  void f(T t) {
+X::g(t);
+  }
+
+  void g() { f(1); }
+  )",
+  R"(
+  struct Y {
+static void g(int);
+static void g(char);
+  };
+
+  template 
+  void f(T t) {
+Y::g(t);
+  }
+
+  void g() { f(1); }
+  )",
+  Lang_CXX03, unresolvedLookupExpr());
+  EXPECT_FALSE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceStmtTest,
+   UnresolvedLookupDifferentTemplateArgument) {
+  auto t = makeStmts(
+  R"(
+  struct A {};
+  template
+  void g() {}
+
+  template 
+  void f() {
+g();
+  }
+
+  void h() { f(); }
+  )",
+  R"(
+  struct B {};
+  template
+  void g() {}
+
+  template 
+  void f() {
+g();
+  }
+
+  void h() { f(); }
+  )",
+  Lang_CXX03, unresolvedLookupExpr());
+  EXPECT_FALSE(testStructuralMatch(t));
+}
+
+TEST_F(StructuralEquivalenceStmtTest, UnresolvedLookup) {
+  auto t = makeStmts(
+  R"(
+  struct A {};
+  struct B {
+template
+static void g(int) {};
+template
+static void g(char) {};
+  };
+
+  template 
+  void f(T2 x) {
+B::g(x);
+  }
+
+  void g() { f(1); }
+  )",
+  R"(
+  struct A {};
+  struct B {
+template
+static void g(int) {};
+template
+static void g(char) {};
+  };
+
+  template 
+  void f(T2 x) {
+B::g(x);
+  }
+
+  void g() { f(1); }
+  )",
+  Lang_CXX03, unresolvedLookupExpr());
+  EXPECT_TRUE(testStructuralMatch(t));
+}
+
 } // end namespace ast_matchers
 } // end namespace clang
Index: clang/lib/AST/ASTStructuralEquivalence.cpp
===
--- clang/lib/AST/ASTStructuralEquivalence.cpp
+++ clang/lib/AST/ASTStructuralEquivalence.cpp
@@ -102,6 +102,9 @@
 static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
  const TemplateArgument &Arg1,
  const TemplateArgument &Arg2);
+static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
+ const TemplateArgumentLoc &Arg1,
+ const TemplateArgumentLoc &Arg2);
 static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
  NestedNameSpecifier *NNS1,
  NestedNameSpecifier *NNS2);
@@ -340,6 +343,30 @@
 return true;
   }
 
+  bool IsStmtEquivalent(const OverloadExpr *E1, const OverloadExpr *E2) {
+if (!IsStructurallyEquivalent(Context, E1->getName(), E2->getName()))
+  return false;
+
+if (static_cast(E1->getQualifier()) !=
+static_cast(E2->getQualifier()))
+  return false;
+if (E1->getQualifier() &&
+!IsStructurallyEquivalent(Context, E1->getQualifier(),
+  E2->getQualifier()))
+  return false;
+
+if (E1->getNumTemplateArgs() != E2->getNumTemplateArgs())
+  return false;
+const TemplateArgumentLoc *Args1 = E1->getTemplateArgs();
+const TemplateArgumentLoc *Args2 = E2->getTemplateArgs();
+for (unsigned int ArgI = 0, ArgN = E1->getNumTemplateArgs(); ArgI < ArgN;
+ ++ArgI)
+  if (!IsStructurallyEquivalent(Context, Args1[ArgI], Args2[ArgI]))
+return false;
+
+return true;
+  }
+
   /// End point of the traversal chain.
   bool TraverseStmt(const Stmt *S1, const Stmt *S2) { retur

[clang] 1118ee0 - [Clang][CGDebugInfo][ObjC] Mark objc bitfields with the DIFlagBitfield flag

2022-12-21 Thread Juan Manuel MARTINEZ CAAMAÑO via cfe-commits

Author: Juan Manuel MARTINEZ CAAMAÑO
Date: 2022-12-21T04:00:40-05:00
New Revision: 1118ee04fc7c09bb54128bcaef4bd82835dcbafd

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

LOG: [Clang][CGDebugInfo][ObjC] Mark objc bitfields with the DIFlagBitfield flag

Reviewed By: aprantl

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

Added: 


Modified: 
clang/lib/CodeGen/CGDebugInfo.cpp
clang/test/CodeGenObjC/debug-info-ivars.m

Removed: 




diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 4d1b0b65d6e8e..576a97b66859c 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2930,6 +2930,9 @@ llvm::DIType *CGDebugInfo::CreateTypeDefinition(const 
ObjCInterfaceType *Ty,
 else if (Field->getAccessControl() == ObjCIvarDecl::Public)
   Flags = llvm::DINode::FlagPublic;
 
+if (Field->isBitField())
+  Flags |= llvm::DINode::FlagBitField;
+
 llvm::MDNode *PropertyNode = nullptr;
 if (ObjCImplementationDecl *ImpD = ID->getImplementation()) {
   if (ObjCPropertyImplDecl *PImpD =

diff  --git a/clang/test/CodeGenObjC/debug-info-ivars.m 
b/clang/test/CodeGenObjC/debug-info-ivars.m
index 996562dae25f1..dc253b2c58abf 100644
--- a/clang/test/CodeGenObjC/debug-info-ivars.m
+++ b/clang/test/CodeGenObjC/debug-info-ivars.m
@@ -30,15 +30,15 @@ @implementation BaseClass
 // CHECK-SAME:   baseType: ![[UNSIGNED:[0-9]+]]
 // CHECK-SAME:   size: 9,
 // CHECK-NOT:offset:
-// CHECK-SAME:   flags: DIFlagProtected
+// CHECK-SAME:   flags: DIFlagProtected | DIFlagBitField
 // CHECK: ![[UNSIGNED]] = !DIBasicType(name: "unsigned int"
 // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "flag_2"
 // CHECK-SAME:   line: 12
 // CHECK-SAME:   baseType: ![[UNSIGNED]]
 // CHECK-SAME:   size: 9, offset: 1,
-// CHECK-SAME:   flags: DIFlagProtected
+// CHECK-SAME:   flags: DIFlagProtected | DIFlagBitField
 // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "flag_3"
 // CHECK-SAME:   line: 14
 // CHECK-SAME:   baseType: ![[UNSIGNED]]
 // CHECK-SAME:   size: 9, offset: 3,
-// CHECK-SAME:   flags: DIFlagProtected
+// CHECK-SAME:   flags: DIFlagProtected | DIFlagBitField



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


[PATCH] D140195: [Clang][CGDebugInfo][ObjC] Mark objc bitfields with the DIFlagBitfield flag

2022-12-21 Thread Juan Manuel Martinez Caamaño via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1118ee04fc7c: [Clang][CGDebugInfo][ObjC] Mark objc bitfields 
with the DIFlagBitfield flag (authored by jmmartinez).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140195

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGenObjC/debug-info-ivars.m


Index: clang/test/CodeGenObjC/debug-info-ivars.m
===
--- clang/test/CodeGenObjC/debug-info-ivars.m
+++ clang/test/CodeGenObjC/debug-info-ivars.m
@@ -30,15 +30,15 @@
 // CHECK-SAME:   baseType: ![[UNSIGNED:[0-9]+]]
 // CHECK-SAME:   size: 9,
 // CHECK-NOT:offset:
-// CHECK-SAME:   flags: DIFlagProtected
+// CHECK-SAME:   flags: DIFlagProtected | DIFlagBitField
 // CHECK: ![[UNSIGNED]] = !DIBasicType(name: "unsigned int"
 // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "flag_2"
 // CHECK-SAME:   line: 12
 // CHECK-SAME:   baseType: ![[UNSIGNED]]
 // CHECK-SAME:   size: 9, offset: 1,
-// CHECK-SAME:   flags: DIFlagProtected
+// CHECK-SAME:   flags: DIFlagProtected | DIFlagBitField
 // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "flag_3"
 // CHECK-SAME:   line: 14
 // CHECK-SAME:   baseType: ![[UNSIGNED]]
 // CHECK-SAME:   size: 9, offset: 3,
-// CHECK-SAME:   flags: DIFlagProtected
+// CHECK-SAME:   flags: DIFlagProtected | DIFlagBitField
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2930,6 +2930,9 @@
 else if (Field->getAccessControl() == ObjCIvarDecl::Public)
   Flags = llvm::DINode::FlagPublic;
 
+if (Field->isBitField())
+  Flags |= llvm::DINode::FlagBitField;
+
 llvm::MDNode *PropertyNode = nullptr;
 if (ObjCImplementationDecl *ImpD = ID->getImplementation()) {
   if (ObjCPropertyImplDecl *PImpD =


Index: clang/test/CodeGenObjC/debug-info-ivars.m
===
--- clang/test/CodeGenObjC/debug-info-ivars.m
+++ clang/test/CodeGenObjC/debug-info-ivars.m
@@ -30,15 +30,15 @@
 // CHECK-SAME:   baseType: ![[UNSIGNED:[0-9]+]]
 // CHECK-SAME:   size: 9,
 // CHECK-NOT:offset:
-// CHECK-SAME:   flags: DIFlagProtected
+// CHECK-SAME:   flags: DIFlagProtected | DIFlagBitField
 // CHECK: ![[UNSIGNED]] = !DIBasicType(name: "unsigned int"
 // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "flag_2"
 // CHECK-SAME:   line: 12
 // CHECK-SAME:   baseType: ![[UNSIGNED]]
 // CHECK-SAME:   size: 9, offset: 1,
-// CHECK-SAME:   flags: DIFlagProtected
+// CHECK-SAME:   flags: DIFlagProtected | DIFlagBitField
 // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "flag_3"
 // CHECK-SAME:   line: 14
 // CHECK-SAME:   baseType: ![[UNSIGNED]]
 // CHECK-SAME:   size: 9, offset: 3,
-// CHECK-SAME:   flags: DIFlagProtected
+// CHECK-SAME:   flags: DIFlagProtected | DIFlagBitField
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2930,6 +2930,9 @@
 else if (Field->getAccessControl() == ObjCIvarDecl::Public)
   Flags = llvm::DINode::FlagPublic;
 
+if (Field->isBitField())
+  Flags |= llvm::DINode::FlagBitField;
+
 llvm::MDNode *PropertyNode = nullptr;
 if (ObjCImplementationDecl *ImpD = ID->getImplementation()) {
   if (ObjCPropertyImplDecl *PImpD =
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D140432: [AArch64] Guard {vmull_p64, vmull_high_p64} with 'aes' target guard.

2022-12-21 Thread Dave Green via Phabricator via cfe-commits
dmgreen accepted this revision.
dmgreen added a comment.
This revision is now accepted and ready to land.

Thanks for putting together the patch. It may be worth mentioning in the commit 
message that aes currently includes both FEAT_AES and FEAT_PMULL.
Otherwise LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140432

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


[PATCH] D140467: [X86][Reduce] Preserve fast math flags when change it. NFCI

2022-12-21 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei created this revision.
pengfei added reviewers: RKSimon, arsenm.
Herald added a project: All.
pengfei requested review of this revision.
Herald added subscribers: cfe-commits, wdng.
Herald added a project: clang.

@arsenm raised a good question that we should use a flag guard.
But I found it is not a problem as long as user uses intrinsics only: 
https://godbolt.org/z/WoYsqqjh3
Anyway, it is still nice to have.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140467

Files:
  clang/lib/CodeGen/CGBuiltin.cpp


Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -14737,8 +14737,11 @@
   case X86::BI__builtin_ia32_reduce_fadd_ph128: {
 Function *F =
 CGM.getIntrinsic(Intrinsic::vector_reduce_fadd, Ops[1]->getType());
+FastMathFlags FMF = Builder.getFastMathFlags();
 Builder.getFastMathFlags().setAllowReassoc();
-return Builder.CreateCall(F, {Ops[0], Ops[1]});
+Value *FAdd = Builder.CreateCall(F, {Ops[0], Ops[1]});
+Builder.getFastMathFlags() &= (FMF);
+return FAdd;
   }
   case X86::BI__builtin_ia32_reduce_fmul_pd512:
   case X86::BI__builtin_ia32_reduce_fmul_ps512:
@@ -14747,8 +14750,11 @@
   case X86::BI__builtin_ia32_reduce_fmul_ph128: {
 Function *F =
 CGM.getIntrinsic(Intrinsic::vector_reduce_fmul, Ops[1]->getType());
+FastMathFlags FMF = Builder.getFastMathFlags();
 Builder.getFastMathFlags().setAllowReassoc();
-return Builder.CreateCall(F, {Ops[0], Ops[1]});
+Value *FMul = Builder.CreateCall(F, {Ops[0], Ops[1]});
+Builder.getFastMathFlags() &= (FMF);
+return FMul;
   }
   case X86::BI__builtin_ia32_reduce_fmax_pd512:
   case X86::BI__builtin_ia32_reduce_fmax_ps512:
@@ -14757,8 +14763,11 @@
   case X86::BI__builtin_ia32_reduce_fmax_ph128: {
 Function *F =
 CGM.getIntrinsic(Intrinsic::vector_reduce_fmax, Ops[0]->getType());
+FastMathFlags FMF = Builder.getFastMathFlags();
 Builder.getFastMathFlags().setNoNaNs();
-return Builder.CreateCall(F, {Ops[0]});
+Value *FMax = Builder.CreateCall(F, {Ops[0]});
+Builder.getFastMathFlags() &= (FMF);
+return FMax;
   }
   case X86::BI__builtin_ia32_reduce_fmin_pd512:
   case X86::BI__builtin_ia32_reduce_fmin_ps512:
@@ -14767,8 +14776,11 @@
   case X86::BI__builtin_ia32_reduce_fmin_ph128: {
 Function *F =
 CGM.getIntrinsic(Intrinsic::vector_reduce_fmin, Ops[0]->getType());
+FastMathFlags FMF = Builder.getFastMathFlags();
 Builder.getFastMathFlags().setNoNaNs();
-return Builder.CreateCall(F, {Ops[0]});
+Value *FMin = Builder.CreateCall(F, {Ops[0]});
+Builder.getFastMathFlags() &= (FMF);
+return FMin;
   }
 
   // 3DNow!


Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -14737,8 +14737,11 @@
   case X86::BI__builtin_ia32_reduce_fadd_ph128: {
 Function *F =
 CGM.getIntrinsic(Intrinsic::vector_reduce_fadd, Ops[1]->getType());
+FastMathFlags FMF = Builder.getFastMathFlags();
 Builder.getFastMathFlags().setAllowReassoc();
-return Builder.CreateCall(F, {Ops[0], Ops[1]});
+Value *FAdd = Builder.CreateCall(F, {Ops[0], Ops[1]});
+Builder.getFastMathFlags() &= (FMF);
+return FAdd;
   }
   case X86::BI__builtin_ia32_reduce_fmul_pd512:
   case X86::BI__builtin_ia32_reduce_fmul_ps512:
@@ -14747,8 +14750,11 @@
   case X86::BI__builtin_ia32_reduce_fmul_ph128: {
 Function *F =
 CGM.getIntrinsic(Intrinsic::vector_reduce_fmul, Ops[1]->getType());
+FastMathFlags FMF = Builder.getFastMathFlags();
 Builder.getFastMathFlags().setAllowReassoc();
-return Builder.CreateCall(F, {Ops[0], Ops[1]});
+Value *FMul = Builder.CreateCall(F, {Ops[0], Ops[1]});
+Builder.getFastMathFlags() &= (FMF);
+return FMul;
   }
   case X86::BI__builtin_ia32_reduce_fmax_pd512:
   case X86::BI__builtin_ia32_reduce_fmax_ps512:
@@ -14757,8 +14763,11 @@
   case X86::BI__builtin_ia32_reduce_fmax_ph128: {
 Function *F =
 CGM.getIntrinsic(Intrinsic::vector_reduce_fmax, Ops[0]->getType());
+FastMathFlags FMF = Builder.getFastMathFlags();
 Builder.getFastMathFlags().setNoNaNs();
-return Builder.CreateCall(F, {Ops[0]});
+Value *FMax = Builder.CreateCall(F, {Ops[0]});
+Builder.getFastMathFlags() &= (FMF);
+return FMax;
   }
   case X86::BI__builtin_ia32_reduce_fmin_pd512:
   case X86::BI__builtin_ia32_reduce_fmin_ps512:
@@ -14767,8 +14776,11 @@
   case X86::BI__builtin_ia32_reduce_fmin_ph128: {
 Function *F =
 CGM.getIntrinsic(Intrinsic::vector_reduce_fmin, Ops[0]->getType());
+FastMathFlags FMF = Builder.getFastMathFlags();
 Builder.getFastMathFlags().setNoNaNs();
-return Builder.CreateCall(F, {Ops[0]});
+Value *FMin = Builder.CreateCall(F, {Ops[0]});
+Builder.get

[PATCH] D140086: [analyzer][solver] Improve reasoning for not equal to operator

2022-12-21 Thread Balázs Benics via Phabricator via cfe-commits
steakhal requested changes to this revision.
steakhal added a comment.
This revision now requires changes to proceed.

>>> Bitwidth was important because we should ideally cast smaller bitwidth type 
>>> to bigger bitwidth type.
>>> Consider if we have LHS(u8), RHS(i32), then without checking for bitwidth, 
>>> we would be casting RHS's maxValue to LHS's type, which will result in lose 
>>> of information and will not serve our purpose.
>>
>> If you think we need that bitwidth check, why did you remove it?
>> I'd like to see test cases demonstrating what we are talking about and see 
>> if we want that behavior or not.
>
> This test fails.
>
>   void testfoo(unsigned char u, signed int s) {
> if (u >= 253 && u <= 255 && s < INT_MAX - 2) {
>   // u: [253, 254], s: [INT_MIN, INT_MAX - 2]
>   clang_analyzer_eval(u != s); // expected-warning{{UNKNOWN}}
>// but returns TRUE
> }
>   }

I feel like we have something to talk about.
When I do the review pro bono, I'd like to focus on higher-level issues and let 
the submitter deal with the smaller concerns.
That's why I'm expecting the submitter to:

- Explain in the summary what the patch aims to solve (aka. why did your work 
on it)
- What & how it implemented it
- What obstacles you had when you tried to implement it? Because the reviewer 
will most likely think the same way, it's better to highlight what you tried 
and why you failed that way.
- Most importantly, attach the test cases you uncovered during development 
about the edge-cases of the previous point.

I'm also expecting that the change compiles, works, and is well-tested. This 
generally means that tests are covering all the branches in the modified parts 
and the change runs and are capable of analyzing non-trivial projects without 
crashing or producing unacceptable reports.
In particular, the `Core` and the range-based solver are the foundation of the 
engine, hence even more rigorous testing is required, so correctness is a must 
in these contexts.

Coming back to this review, I don't want to validate the correctness of the 
math. I trust you to do this, which you prove by tests or (Z3 solution in 
addition to that).
Getting more concrete, returning `Unknown` is fine, but returning the wrong 
answer like `True` for cases where we should not be able to deduce it, it's a 
serious issue.

I hope it helps to align us.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140086

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


[PATCH] D140467: [X86][Reduce] Preserve fast math flags when change it. NFCI

2022-12-21 Thread Sergei Barannikov via Phabricator via cfe-commits
barannikov88 added inline comments.



Comment at: clang/lib/CodeGen/CGBuiltin.cpp:14742
 Builder.getFastMathFlags().setAllowReassoc();
-return Builder.CreateCall(F, {Ops[0], Ops[1]});
+Value *FAdd = Builder.CreateCall(F, {Ops[0], Ops[1]});
+Builder.getFastMathFlags() &= (FMF);

Could be just:
```
return Builder.CreateCall(F, {Ops[0], Ops[1]})
->getFastMathFlags()
.setAllowReassoc();
```
so that you don't have to save and restore Builder's flags.



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140467

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


[PATCH] D140467: [X86][Reduce] Preserve fast math flags when change it. NFCI

2022-12-21 Thread Sergei Barannikov via Phabricator via cfe-commits
barannikov88 added inline comments.



Comment at: clang/lib/CodeGen/CGBuiltin.cpp:14742
 Builder.getFastMathFlags().setAllowReassoc();
-return Builder.CreateCall(F, {Ops[0], Ops[1]});
+Value *FAdd = Builder.CreateCall(F, {Ops[0], Ops[1]});
+Builder.getFastMathFlags() &= (FMF);

barannikov88 wrote:
> Could be just:
> ```
> return Builder.CreateCall(F, {Ops[0], Ops[1]})
> ->getFastMathFlags()
> .setAllowReassoc();
> ```
> so that you don't have to save and restore Builder's flags.
> 
No, it couldn't be, just tried :(


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140467

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


[PATCH] D140361: [RISCV] Merge Masked and unMasked RVV manual codegen

2022-12-21 Thread Piyou Chen via Phabricator via cfe-commits
BeMg updated this revision to Diff 484498.
BeMg added a comment.

rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140361

Files:
  clang/include/clang/Basic/riscv_vector.td
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/utils/TableGen/RISCVVEmitter.cpp

Index: clang/utils/TableGen/RISCVVEmitter.cpp
===
--- clang/utils/TableGen/RISCVVEmitter.cpp
+++ clang/utils/TableGen/RISCVVEmitter.cpp
@@ -171,6 +171,10 @@
 
   if (RVVI->hasManualCodegen()) {
 OS << "  DefaultPolicy = " << RVVI->getDefaultPolicyBits() << ";\n";
+if (RVVI->isMasked())
+  OS << "IsMasked = true;\n";
+else
+  OS << "IsMasked = false;\n";
 OS << RVVI->getManualCodegen();
 OS << "break;\n";
 return;
@@ -517,7 +521,6 @@
 bool SupportOverloading = R->getValueAsBit("SupportOverloading");
 bool HasBuiltinAlias = R->getValueAsBit("HasBuiltinAlias");
 StringRef ManualCodegen = R->getValueAsString("ManualCodegen");
-StringRef MaskedManualCodegen = R->getValueAsString("MaskedManualCodegen");
 std::vector IntrinsicTypes =
 R->getValueAsListOfInts("IntrinsicTypes");
 std::vector RequiredFeatures =
@@ -598,7 +601,7 @@
 Out.push_back(std::make_unique(
 Name, SuffixStr, OverloadedName, OverloadedSuffixStr, MaskedIRName,
 /*IsMasked=*/true, HasMaskedOffOperand, HasVL, MaskedPolicyScheme,
-SupportOverloading, HasBuiltinAlias, MaskedManualCodegen,
+SupportOverloading, HasBuiltinAlias, ManualCodegen,
 *MaskTypes, IntrinsicTypes, RequiredFeatures, NF,
 Policy(), IsPrototypeDefaultTU));
 if (MaskedPolicyScheme == PolicyScheme::SchemeNone)
@@ -614,7 +617,7 @@
   Name, SuffixStr, OverloadedName, OverloadedSuffixStr,
   MaskedIRName, /*IsMasked=*/true, HasMaskedOffOperand, HasVL,
   MaskedPolicyScheme, SupportOverloading, HasBuiltinAlias,
-  MaskedManualCodegen, *PolicyTypes, IntrinsicTypes,
+  ManualCodegen, *PolicyTypes, IntrinsicTypes,
   RequiredFeatures, NF, P, IsPrototypeDefaultTU));
 }
   } // End for Log2LMULList
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -19438,6 +19438,7 @@
   constexpr unsigned TAIL_AGNOSTIC = 1;
   constexpr unsigned TAIL_AGNOSTIC_MASK_AGNOSTIC = 3;
   int DefaultPolicy = TAIL_UNDISTURBED;
+  bool IsMasked = false;
 
   // Required for overloaded intrinsics.
   llvm::SmallVector IntrinsicTypes;
Index: clang/include/clang/Basic/riscv_vector.td
===
--- clang/include/clang/Basic/riscv_vector.td
+++ clang/include/clang/Basic/riscv_vector.td
@@ -217,7 +217,6 @@
 
   // Manual code in clang codegen riscv_vector_builtin_cg.inc
   code ManualCodegen = [{}];
-  code MaskedManualCodegen = [{}];
 
   // When emit the automatic clang codegen, it describes what types we have to use
   // to obtain the specific LLVM intrinsic. -1 means the return type, otherwise,
@@ -627,31 +626,18 @@
   UnMaskedPolicyScheme = HasPassthruOperand,
   ManualCodegen = [{
   {
-if (DefaultPolicy == TAIL_AGNOSTIC)
-  Ops.insert(Ops.begin(), llvm::PoisonValue::get(ResultType));
-IntrinsicTypes = {ResultType, Ops[3]->getType()};
-Ops[1] = Builder.CreateBitCast(Ops[1], ResultType->getPointerTo());
-Value *NewVL = Ops[2];
-Ops.erase(Ops.begin() + 2);
-llvm::Function *F = CGM.getIntrinsic(ID, IntrinsicTypes);
-llvm::Value *LoadValue = Builder.CreateCall(F, Ops, "");
-llvm::Value *V = Builder.CreateExtractValue(LoadValue, {0});
-// Store new_vl.
-clang::CharUnits Align =
-CGM.getNaturalPointeeTypeAlignment(E->getArg(1)->getType());
-llvm::Value *Val = Builder.CreateExtractValue(LoadValue, {1});
-Builder.CreateStore(Val, Address(NewVL, Val->getType(), Align));
-return V;
-  }
-  }],
-  MaskedManualCodegen = [{
-  {
-// Move mask to right before vl.
-std::rotate(Ops.begin(), Ops.begin() + 1, Ops.end() - 1);
-if (DefaultPolicy == TAIL_AGNOSTIC_MASK_AGNOSTIC)
-  Ops.insert(Ops.begin(), llvm::PoisonValue::get(ResultType));
-Ops.push_back(ConstantInt::get(Ops.back()->getType(), DefaultPolicy));
-IntrinsicTypes = {ResultType, Ops[4]->getType()};
+if (IsMasked) {
+  // Move mask to right before vl.
+  std::rotate(Ops.begin(), Ops.begin() + 1, Ops.end() - 1);
+  if (DefaultPolicy == TAIL_AGNOSTIC_MASK_AGNOSTIC)
+Ops.insert(Ops.begin(), llvm::PoisonValue::get(ResultType));
+  Ops.push_back(ConstantInt::get(Ops.back()->getType(), DefaultPolicy));
+  Intr

[PATCH] D135750: [clang][Interp] Track initialization state of local variables

2022-12-21 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder marked 4 inline comments as done.
tbaeder added inline comments.



Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:835
 IsTemporary = true;
 Ty = E->getType();
   }

shafik wrote:
> tbaeder wrote:
> > shafik wrote:
> > > Do we really want to the type of the expression? If we have a `ValueDecl` 
> > > don't we want that type? I think they should be the same, do you have any 
> > > examples where the expression is the type we want? I am looking at the 
> > > AST from ` int x = 1+1L;` 
> > > 
> > > https://godbolt.org/z/q3Tr7Kxoq
> > I don't have a counter example but I didn't write that line either. The 
> > Expr case is for temporary values created for AST expressions, not sure 
> > what other type to use.
> I think it should be an `else if` we either have a `Decl` or an `Expr` right?
Yes, that should work as well.



Comment at: clang/lib/AST/Interp/ByteCodeStmtGen.cpp:408
 // Compile the initializer in its own scope.
-{
+if (Init) {
   ExprScope Scope(this);

shafik wrote:
> So by moving the check for `Init` forward, we will still allocate but we may 
> not initialize.
Correct.



Comment at: clang/lib/AST/Interp/Interp.h:918
 return false;
+  if (!Ptr.isRoot())
+Ptr.initialize();

shafik wrote:
> Can you explain what is going on here? Why do we need to initialize if it is 
> not root?
Root means that `Base == 0`, so it cannot have a `InlineDescriptor` before the 
`Base` offset. That is mainly the case for global variables.


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

https://reviews.llvm.org/D135750

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


[PATCH] D135750: [clang][Interp] Track initialization state of local variables

2022-12-21 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 484499.
tbaeder marked 2 inline comments as done.

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

https://reviews.llvm.org/D135750

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeStmtGen.cpp
  clang/lib/AST/Interp/Context.cpp
  clang/lib/AST/Interp/Descriptor.cpp
  clang/lib/AST/Interp/Descriptor.h
  clang/lib/AST/Interp/EvalEmitter.cpp
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/InterpBlock.h
  clang/lib/AST/Interp/InterpFrame.cpp
  clang/lib/AST/Interp/InterpFrame.h
  clang/lib/AST/Interp/Pointer.cpp
  clang/lib/AST/Interp/Pointer.h
  clang/lib/AST/Interp/Program.cpp
  clang/lib/AST/Interp/Program.h
  clang/test/AST/Interp/cxx20.cpp
  clang/test/AST/Interp/literals.cpp
  clang/test/AST/Interp/loops.cpp

Index: clang/test/AST/Interp/loops.cpp
===
--- clang/test/AST/Interp/loops.cpp
+++ clang/test/AST/Interp/loops.cpp
@@ -5,6 +5,7 @@
 
 // ref-no-diagnostics
 // expected-no-diagnostics
+// expected-cpp20-no-diagnostics
 
 namespace WhileLoop {
   constexpr int f() {
@@ -165,8 +166,6 @@
   static_assert(f5(true) == 8, "");
   static_assert(f5(false) == 5, "");
 
-  /// FIXME: This should be accepted in C++20 but is currently being rejected
-  ///   because the variable declaration doesn't have an initializier.
 #if __cplusplus >= 202002L
   constexpr int f6() {
 int i;
@@ -176,7 +175,7 @@
 } while (true);
 return i;
   }
-  static_assert(f6() == 5, ""); // expected-cpp20-error {{not an integral constant}}
+  static_assert(f6() == 5, "");
 #endif
 
 #if 0
Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -407,8 +407,7 @@
 return 1;
   }
   static_assert(uninit(), ""); // ref-error {{not an integral constant expression}} \
-   // ref-note {{in call to 'uninit()'}} \
-   // expected-error {{not an integral constant expression}}
+   // ref-note {{in call to 'uninit()'}}
 
   constexpr int OverFlow() { // ref-error {{never produces a constant expression}}
 int a = INT_MAX;
Index: clang/test/AST/Interp/cxx20.cpp
===
--- clang/test/AST/Interp/cxx20.cpp
+++ clang/test/AST/Interp/cxx20.cpp
@@ -56,33 +56,51 @@
 }
 static_assert(pointerAssign2() == 12, "");
 
-
 constexpr int unInitLocal() {
   int a;
-  return a; // ref-note{{read of uninitialized object}}
+  return a; // ref-note {{read of uninitialized object}} \
+// expected-note {{read of object outside its lifetime}}
+// FIXME: ^^^ Wrong diagnostic.
 }
-static_assert(unInitLocal() == 0, ""); // expected-error {{not an integral constant expression}} \
-   // ref-error {{not an integral constant expression}} \
-   // ref-note {{in call to 'unInitLocal()'}}
-
-/// TODO: The example above is correctly rejected by the new constexpr
-///   interpreter, but for the wrong reasons. We don't reject it because
-///   it is an uninitialized read, we reject it simply because
-///   the local variable does not have an initializer.
-///
-///   The code below should be accepted but is also being rejected
-///   right now.
-#if 0
+static_assert(unInitLocal() == 0, ""); // ref-error {{not an integral constant expression}} \
+   // ref-note {{in call to 'unInitLocal()'}} \
+   // expected-error {{not an integral constant expression}} \
+   // expected-note {{in call to 'unInitLocal()'}} \
+
 constexpr int initializedLocal() {
   int a;
-  int b;
-
   a = 20;
   return a;
 }
 static_assert(initializedLocal() == 20);
 
-/// Similar here, but the uninitialized local is passed as a function parameter.
+constexpr int initializedLocal2() {
+  int a[2];
+  return *a; // expected-note {{read of object outside its lifetime}} \
+ // ref-note {{read of uninitialized object is not allowed in a constant expression}}
+}
+static_assert(initializedLocal2() == 20); // expected-error {{not an integral constant expression}} \
+  // expected-note {{in call to}} \
+  // ref-error {{not an integral constant expression}} \
+  // ref-note {{in call to}}
+
+
+struct Int { int a; };
+constexpr int initializedLocal3() {
+  Int i;
+  return i.a; // expected-note {{read of object outside its lifetime}} \
+  // ref-note {{read of uninitialized object is not allowed in a constant expression}}
+}
+static_assert(initializedLocal3() == 20); // expected-error {{not an integral constant expression}} \
+ 

[PATCH] D136815: [clang][Interp] Unify visiting variable declarations

2022-12-21 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added inline comments.



Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:1218
+auto GlobalIndex = P.getGlobal(VD);
+assert(GlobalIndex); // visitVarDecl() didn't return false.
+if (!this->emitGetPtrGlobal(*GlobalIndex, VD))

shafik wrote:
> I don't get the comment.
`P.getGlobal()` must return a global index and not `std::nullopt`, since the 
`visitVarDecl()` call above did not return `false`. It will return `false` if 
something failed, but it didn't and so the variable must be allocated already.


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

https://reviews.llvm.org/D136815

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


[PATCH] D137070: [clang][Interp] Support destructors

2022-12-21 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder marked 2 inline comments as done.
tbaeder added inline comments.



Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:30
 /// Scope used to handle temporaries in toplevel variable declarations.
-template  class DeclScope final : public LocalScope {
+template  class DeclScope final : public VariableScope 
{
 public:

shafik wrote:
> Why the change from `LocalScope` to `VariableScope`?
I changed `VariableScope` to do the destructor handling, bu that's not needed 
for "temporaries in toplevel variable desclarations" (also, but unrelated, 
inherting from something called "local scope" but then explaining in a comment 
that it's only used for toplevel declarations is kinda weird).


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

https://reviews.llvm.org/D137070

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


[PATCH] D137070: [clang][Interp] Support destructors

2022-12-21 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 484500.

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

https://reviews.llvm.org/D137070

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/lib/AST/Interp/ByteCodeStmtGen.cpp
  clang/test/AST/Interp/cxx20.cpp

Index: clang/test/AST/Interp/cxx20.cpp
===
--- clang/test/AST/Interp/cxx20.cpp
+++ clang/test/AST/Interp/cxx20.cpp
@@ -219,3 +219,114 @@
// ref-error {{must be initialized by a constant expression}}
 
 };
+
+namespace Destructors {
+
+  class Inc final {
+  public:
+int &I;
+constexpr Inc(int &I) : I(I) {}
+constexpr ~Inc() {
+  I++;
+}
+  };
+
+  class Dec final {
+  public:
+int &I;
+constexpr Dec(int &I) : I(I) {}
+constexpr ~Dec() {
+  I--;
+}
+  };
+
+
+
+  constexpr int m() {
+int i = 0;
+{
+  Inc f1(i);
+  Inc f2(i);
+  Inc f3(i);
+}
+return i;
+  }
+  static_assert(m() == 3, "");
+
+
+  constexpr int C() {
+int i = 0;
+
+while (i < 10) {
+  Inc inc(i);
+  continue;
+  Dec dec(i);
+}
+return i;
+  }
+  static_assert(C() == 10, "");
+
+
+  constexpr int D() {
+int i = 0;
+
+{
+  Inc i1(i);
+  {
+Inc i2(i);
+return i;
+  }
+}
+
+return i;
+  }
+  static_assert(D() == 0, "");
+
+  constexpr int E() {
+int i = 0;
+
+for(;;) {
+  Inc i1(i);
+  break;
+}
+return i;
+  }
+  static_assert(E() == 1, "");
+
+
+  /// FIXME: This should be rejected, since we call the destructor
+  ///   twice. However, GCC doesn't care either.
+  constexpr int ManualDtor() {
+int i = 0;
+{
+  Inc I(i); // ref-note {{destroying object 'I' whose lifetime has already ended}}
+  I.~Inc();
+}
+return i;
+  }
+  static_assert(ManualDtor() == 1, ""); // expected-error {{static assertion failed}} \
+// expected-note {{evaluates to '2 == 1'}} \
+// ref-error {{not an integral constant expression}} \
+// ref-note {{in call to 'ManualDtor()'}}
+
+  constexpr void doInc(int &i) {
+Inc I(i);
+return;
+  }
+  constexpr int testInc() {
+int i = 0;
+doInc(i);
+return i;
+  }
+  static_assert(testInc() == 1, "");
+  constexpr void doInc2(int &i) {
+Inc I(i);
+// No return statement.
+  }
+   constexpr int testInc2() {
+int i = 0;
+doInc2(i);
+return i;
+  }
+  static_assert(testInc2() == 1, "");
+}
Index: clang/lib/AST/Interp/ByteCodeStmtGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeStmtGen.cpp
+++ clang/lib/AST/Interp/ByteCodeStmtGen.cpp
@@ -380,6 +380,7 @@
   if (!BreakLabel)
 return false;
 
+  this->emitCleanup();
   return this->jump(*BreakLabel);
 }
 
@@ -388,6 +389,7 @@
   if (!ContinueLabel)
 return false;
 
+  this->emitCleanup();
   return this->jump(*ContinueLabel);
 }
 
Index: clang/lib/AST/Interp/ByteCodeExprGen.h
===
--- clang/lib/AST/Interp/ByteCodeExprGen.h
+++ clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -330,7 +330,7 @@
 public:
   LocalScope(ByteCodeExprGen *Ctx) : VariableScope(Ctx) {}
 
-  ~LocalScope() override { this->emitDestruction(); }
+  virtual ~LocalScope() override { this->emitDestruction(); }
 
   void addLocal(const Scope::Local &Local) override {
 if (!Idx) {
@@ -344,6 +344,29 @@
   void emitDestruction() override {
 if (!Idx)
   return;
+
+// Emit destructor calls for local variables of record
+// type with a destructor.
+for (Scope::Local &Local : this->Ctx->Descriptors[*Idx]) {
+  const Record *TypeRecord = Local.Desc->ElemRecord;
+  if (!TypeRecord)
+continue;
+
+  const auto *RDecl = dyn_cast(TypeRecord->getDecl());
+  if (!RDecl)
+continue;
+
+  if (const auto *DtorDecl = RDecl->getDestructor()) {
+const Function *Dtor = this->Ctx->getFunction(DtorDecl);
+if (Dtor && Dtor->isConstexpr()) {
+  assert(Dtor->hasThisPointer());
+  assert(Dtor->getNumParams() == 1);
+  // Emit destructor call.
+  this->Ctx->emitGetPtrLocal(Local.Offset, DtorDecl);
+  this->Ctx->emitCall(Dtor, DtorDecl);
+}
+  }
+}
 this->Ctx->emitDestroy(*Idx, SourceInfo{});
   }
 
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -26,10 +26,12 @@
 namespace interp {
 
 /// Scope used to handle temporaries in toplevel variable declarations.
-template  class DeclScope final : public LocalScope {
+template  class DeclScope final : public VariableScope {
 public:
   DeclScope(ByteCodeExprGen *C

[PATCH] D140467: [X86][Reduce] Preserve fast math flags when change it. NFCI

2022-12-21 Thread Jay Foad via Phabricator via cfe-commits
foad added inline comments.



Comment at: clang/lib/CodeGen/CGBuiltin.cpp:14740
 CGM.getIntrinsic(Intrinsic::vector_reduce_fadd, Ops[1]->getType());
+FastMathFlags FMF = Builder.getFastMathFlags();
 Builder.getFastMathFlags().setAllowReassoc();

We have FastMathFlagGuard for automatically saving and restoring fast math 
flags.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140467

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


[PATCH] D140467: [X86][Reduce] Preserve fast math flags when change it. NFCI

2022-12-21 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added a comment.

Needs tests. I couldn’t find any for the base builtins either


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140467

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


[PATCH] D140467: [X86][Reduce] Preserve fast math flags when change it. NFCI

2022-12-21 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei updated this revision to Diff 484521.
pengfei marked an inline comment as done.
pengfei added a comment.

Use FastMathFlagGuard instead, thanks @foad!

In D140467#4010296 , @arsenm wrote:

> Needs tests. I couldn’t find any for the base builtins either

I don't think so. We have tested their intrinsic wrappers, e.g., 
https://github.com/llvm/llvm-project/blob/main/clang/test/CodeGen/X86/avx512fp16-builtins.c#L4451

We don't need to test those target specific builtins. They are neither 
guaranteed to be cross compiler compatible nor release by release.

Besides, we have thousands of intrinsics in X86. Adding their builtin tests 
have no any benefits and increase the time in lit tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140467

Files:
  clang/lib/CodeGen/CGBuiltin.cpp


Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -13113,6 +13113,8 @@
 return Builder.CreateBitCast(Sext, FPVecTy);
   };
 
+  IRBuilder<>::FastMathFlagGuard FMFGuard(Builder);
+
   switch (BuiltinID) {
   default: return nullptr;
   case X86::BI_mm_prefetch: {


Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -13113,6 +13113,8 @@
 return Builder.CreateBitCast(Sext, FPVecTy);
   };
 
+  IRBuilder<>::FastMathFlagGuard FMFGuard(Builder);
+
   switch (BuiltinID) {
   default: return nullptr;
   case X86::BI_mm_prefetch: {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D140467: [X86][Reduce] Preserve fast math flags when change it. NFCI

2022-12-21 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei added inline comments.



Comment at: clang/lib/CodeGen/CGBuiltin.cpp:14742
 Builder.getFastMathFlags().setAllowReassoc();
-return Builder.CreateCall(F, {Ops[0], Ops[1]});
+Value *FAdd = Builder.CreateCall(F, {Ops[0], Ops[1]});
+Builder.getFastMathFlags() &= (FMF);

barannikov88 wrote:
> barannikov88 wrote:
> > Could be just:
> > ```
> > return Builder.CreateCall(F, {Ops[0], Ops[1]})
> > ->getFastMathFlags()
> > .setAllowReassoc();
> > ```
> > so that you don't have to save and restore Builder's flags.
> > 
> No, it couldn't be, just tried :(
Thanks for trying it :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140467

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


[clang] b2638a7 - [clang] Do not extend i8 return values to i16 on AVR.

2022-12-21 Thread Ben Shi via cfe-commits

Author: Ben Shi
Date: 2022-12-21T20:33:49+08:00
New Revision: b2638a7a34d97066caa234999055bf580cbab02f

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

LOG: [clang] Do not extend i8 return values to i16 on AVR.

Reviewed By: Miss_Grape, aykevl

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

Added: 


Modified: 
clang/lib/CodeGen/TargetInfo.cpp
clang/test/CodeGen/avr/avr-builtins.c

Removed: 




diff  --git a/clang/lib/CodeGen/TargetInfo.cpp 
b/clang/lib/CodeGen/TargetInfo.cpp
index 98b54dfb1651f..aec170ae55706 100644
--- a/clang/lib/CodeGen/TargetInfo.cpp
+++ b/clang/lib/CodeGen/TargetInfo.cpp
@@ -8445,6 +8445,10 @@ class AVRABIInfo : public DefaultABIInfo {
   LargeRet = true;
   return getNaturalAlignIndirect(Ty);
 }
+// An i8 return value should not be extended to i16, since AVR has 8-bit
+// registers.
+if (Ty->isIntegralOrEnumerationType() && getContext().getTypeSize(Ty) <= 8)
+  return ABIArgInfo::getDirect();
 // Otherwise we follow the default way which is compatible.
 return DefaultABIInfo::classifyReturnType(Ty);
   }

diff  --git a/clang/test/CodeGen/avr/avr-builtins.c 
b/clang/test/CodeGen/avr/avr-builtins.c
index bdecff3fc38a8..7c2c424848080 100644
--- a/clang/test/CodeGen/avr/avr-builtins.c
+++ b/clang/test/CodeGen/avr/avr-builtins.c
@@ -8,7 +8,7 @@ unsigned char bitrev8(unsigned char data) {
 return __builtin_bitreverse8(data);
 }
 
-// CHECK: define{{.*}} zeroext i8 @bitrev8
+// CHECK: define{{.*}} i8 @bitrev8
 // CHECK: i8 @llvm.bitreverse.i8(i8
 
 unsigned int bitrev16(unsigned int data) {
@@ -35,7 +35,7 @@ unsigned char rotleft8(unsigned char x, unsigned char y) {
 return __builtin_rotateleft8(x, y);
 }
 
-// CHECK: define{{.*}} zeroext i8 @rotleft8
+// CHECK: define{{.*}} i8 @rotleft8
 // CHECK: i8 @llvm.fshl.i8(i8
 
 unsigned int rotleft16(unsigned int x, unsigned int y) {
@@ -62,7 +62,7 @@ unsigned char rotright8(unsigned char x, unsigned char y) {
 return __builtin_rotateright8(x, y);
 }
 
-// CHECK: define{{.*}} zeroext i8 @rotright8
+// CHECK: define{{.*}} i8 @rotright8
 // CHECK: i8 @llvm.fshr.i8(i8
 
 unsigned int rotright16(unsigned int x, unsigned int y) {



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


[PATCH] D139908: [clang] Do not extend i8 return values to i16 on AVR.

2022-12-21 Thread Ben Shi via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb2638a7a34d9: [clang] Do not extend i8 return values to i16 
on AVR. (authored by benshi001).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139908

Files:
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/CodeGen/avr/avr-builtins.c


Index: clang/test/CodeGen/avr/avr-builtins.c
===
--- clang/test/CodeGen/avr/avr-builtins.c
+++ clang/test/CodeGen/avr/avr-builtins.c
@@ -8,7 +8,7 @@
 return __builtin_bitreverse8(data);
 }
 
-// CHECK: define{{.*}} zeroext i8 @bitrev8
+// CHECK: define{{.*}} i8 @bitrev8
 // CHECK: i8 @llvm.bitreverse.i8(i8
 
 unsigned int bitrev16(unsigned int data) {
@@ -35,7 +35,7 @@
 return __builtin_rotateleft8(x, y);
 }
 
-// CHECK: define{{.*}} zeroext i8 @rotleft8
+// CHECK: define{{.*}} i8 @rotleft8
 // CHECK: i8 @llvm.fshl.i8(i8
 
 unsigned int rotleft16(unsigned int x, unsigned int y) {
@@ -62,7 +62,7 @@
 return __builtin_rotateright8(x, y);
 }
 
-// CHECK: define{{.*}} zeroext i8 @rotright8
+// CHECK: define{{.*}} i8 @rotright8
 // CHECK: i8 @llvm.fshr.i8(i8
 
 unsigned int rotright16(unsigned int x, unsigned int y) {
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -8445,6 +8445,10 @@
   LargeRet = true;
   return getNaturalAlignIndirect(Ty);
 }
+// An i8 return value should not be extended to i16, since AVR has 8-bit
+// registers.
+if (Ty->isIntegralOrEnumerationType() && getContext().getTypeSize(Ty) <= 8)
+  return ABIArgInfo::getDirect();
 // Otherwise we follow the default way which is compatible.
 return DefaultABIInfo::classifyReturnType(Ty);
   }


Index: clang/test/CodeGen/avr/avr-builtins.c
===
--- clang/test/CodeGen/avr/avr-builtins.c
+++ clang/test/CodeGen/avr/avr-builtins.c
@@ -8,7 +8,7 @@
 return __builtin_bitreverse8(data);
 }
 
-// CHECK: define{{.*}} zeroext i8 @bitrev8
+// CHECK: define{{.*}} i8 @bitrev8
 // CHECK: i8 @llvm.bitreverse.i8(i8
 
 unsigned int bitrev16(unsigned int data) {
@@ -35,7 +35,7 @@
 return __builtin_rotateleft8(x, y);
 }
 
-// CHECK: define{{.*}} zeroext i8 @rotleft8
+// CHECK: define{{.*}} i8 @rotleft8
 // CHECK: i8 @llvm.fshl.i8(i8
 
 unsigned int rotleft16(unsigned int x, unsigned int y) {
@@ -62,7 +62,7 @@
 return __builtin_rotateright8(x, y);
 }
 
-// CHECK: define{{.*}} zeroext i8 @rotright8
+// CHECK: define{{.*}} i8 @rotright8
 // CHECK: i8 @llvm.fshr.i8(i8
 
 unsigned int rotright16(unsigned int x, unsigned int y) {
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -8445,6 +8445,10 @@
   LargeRet = true;
   return getNaturalAlignIndirect(Ty);
 }
+// An i8 return value should not be extended to i16, since AVR has 8-bit
+// registers.
+if (Ty->isIntegralOrEnumerationType() && getContext().getTypeSize(Ty) <= 8)
+  return ABIArgInfo::getDirect();
 // Otherwise we follow the default way which is compatible.
 return DefaultABIInfo::classifyReturnType(Ty);
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D140467: [X86][Reduce] Preserve fast math flags when change it. NFCI

2022-12-21 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm requested changes to this revision.
arsenm added a comment.
This revision now requires changes to proceed.

In D140467#4010378 , @pengfei wrote:

> Use FastMathFlagGuard instead, thanks @foad!
>
> In D140467#4010296 , @arsenm wrote:
>
>> Needs tests. I couldn’t find any for the base builtins either
>
> I don't think so. We have tested their intrinsic wrappers, e.g., 
> https://github.com/llvm/llvm-project/blob/main/clang/test/CodeGen/X86/avx512fp16-builtins.c#L4451

These are not testing use of these builtins correctly

> We don't need to test those target specific builtins. They are neither 
> guaranteed to be cross compiler compatible nor release by release.

If it exists it must be tested.

> Besides, we have thousands of intrinsics in X86. Adding their builtin tests 
> have no any benefits and increase the time in lit tests.

Every piece of code generation needs to be tested.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140467

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


[clang] 016785d - [clang/xray] Convert tests to check 'target=...'

2022-12-21 Thread Paul Robinson via cfe-commits

Author: Paul Robinson
Date: 2022-12-21T05:19:27-08:00
New Revision: 016785d9316d8c5abc5fdf3cdb86479095bbb677

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

LOG: [clang/xray] Convert tests to check 'target=...'

Part of the project to eliminate special handling for triples in lit
expressions.

Added: 


Modified: 
clang/test/Driver/XRay/lit.local.cfg
clang/test/Driver/XRay/xray-instrument-cpu.c
clang/test/Driver/XRay/xray-instrument-os.c

Removed: 




diff  --git a/clang/test/Driver/XRay/lit.local.cfg 
b/clang/test/Driver/XRay/lit.local.cfg
index 70f9792ba3db5..1755d9ab5ce9e 100644
--- a/clang/test/Driver/XRay/lit.local.cfg
+++ b/clang/test/Driver/XRay/lit.local.cfg
@@ -1,6 +1,4 @@
 import platform
-target_triple_components = config.target_triple.split('-')
-config.available_features.update(target_triple_components)
 
 # Only run the tests in platforms where XRay instrumentation is supported.
 supported_targets = [
@@ -13,7 +11,7 @@ supported_oses = [
 'Linux', 'FreeBSD', 'Darwin'
 ]
 
-triple_set = set(target_triple_components)
+triple_set = set(config.target_triple.split('-'))
 if len(triple_set.intersection(supported_targets)) == 0:
   config.unsupported = True
 

diff  --git a/clang/test/Driver/XRay/xray-instrument-cpu.c 
b/clang/test/Driver/XRay/xray-instrument-cpu.c
index ee0e0984b36d8..a8bc2a6431335 100644
--- a/clang/test/Driver/XRay/xray-instrument-cpu.c
+++ b/clang/test/Driver/XRay/xray-instrument-cpu.c
@@ -1,4 +1,5 @@
 // RUN: not %clang -o /dev/null -v -fxray-instrument -c %s
-// XFAIL: amd64-, x86_64-, x86_64h-, arm, aarch64, arm64, powerpc64le-, mips, 
mipsel, mips64, mips64el
+// XFAIL: target={{(amd64|x86_64|x86_64h|powerpc64le)-.*}}
+// XFAIL: target={{(arm|aarch64|arm64|mips|mipsel|mips64|mips64el)-.*}}
 // REQUIRES: linux
 typedef int a;

diff  --git a/clang/test/Driver/XRay/xray-instrument-os.c 
b/clang/test/Driver/XRay/xray-instrument-os.c
index 3a0397208326f..7a4f1c13cb0b1 100644
--- a/clang/test/Driver/XRay/xray-instrument-os.c
+++ b/clang/test/Driver/XRay/xray-instrument-os.c
@@ -1,4 +1,4 @@
 // RUN: not %clang -o /dev/null -v -fxray-instrument -c %s
-// XFAIL: -linux-, -freebsd, x86_64-apple-darwin, x86_64-apple-macos
-// REQUIRES: amd64 || x86_64 || x86_64h || arm || aarch64 || arm64
+// XFAIL: target={{.*-(linux|freebsd).*}}, 
target=x86_64-apple-{{(darwin|macos).*}}
+// REQUIRES: target={{(amd64|x86_64|x86_64h|arm|aarch64|arm64)-.*}}
 typedef int a;



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


[PATCH] D140467: [X86][Reduce] Preserve fast math flags when change it. NFCI

2022-12-21 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added a comment.

In D140467#4010507 , @arsenm wrote:

> In D140467#4010378 , @pengfei wrote:
>
>> Use FastMathFlagGuard instead, thanks @foad!
>>
>> In D140467#4010296 , @arsenm wrote:
>>
>>> Needs tests. I couldn’t find any for the base builtins either
>>
>> I don't think so. We have tested their intrinsic wrappers, e.g., 
>> https://github.com/llvm/llvm-project/blob/main/clang/test/CodeGen/X86/avx512fp16-builtins.c#L4451
>
> These are not testing use of these builtins correctly

This test amounts to a builtin header test for immintrin.h. This should move to 
clang/test/Headers and replaced with a builtin test directly checking the 
builtin handling


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140467

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


[clang] 947905a - clang: Use correct address space for redeclared functions

2022-12-21 Thread Matt Arsenault via cfe-commits

Author: Matt Arsenault
Date: 2022-12-21T08:27:24-05:00
New Revision: 947905a1c5843b677849c3c4fadb524b6405c139

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

LOG: clang: Use correct address space for redeclared functions

Fixes assert/verifier error with AVR.

Added: 
clang/test/CodeGen/redeclare-function-addrspace.c

Modified: 
clang/lib/CodeGen/CodeGenModule.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index c8783ea8578d..50e2f5bf212e 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -4056,7 +4056,7 @@ llvm::Constant *CodeGenModule::GetOrCreateLLVMFunction(
 }
 
 llvm::Constant *BC = llvm::ConstantExpr::getBitCast(
-F, Entry->getValueType()->getPointerTo());
+F, Entry->getValueType()->getPointerTo(Entry->getAddressSpace()));
 addGlobalValReplacement(Entry, BC);
   }
 

diff  --git a/clang/test/CodeGen/redeclare-function-addrspace.c 
b/clang/test/CodeGen/redeclare-function-addrspace.c
new file mode 100644
index ..bb434b99812d
--- /dev/null
+++ b/clang/test/CodeGen/redeclare-function-addrspace.c
@@ -0,0 +1,54 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --function-signature
+// REQUIRES: avr-registered-target
+// RUN: %clang_cc1 -triple avr-- -Wno-strict-prototypes 
-Wno-deprecated-non-prototype -emit-llvm -o - -verify %s | FileCheck %s
+// expected-no-diagnostics
+
+// Make sure redeclarations of functions as a 
diff erent type work when functions
+// use non-0 address spaces.
+
+int g();
+
+// CHECK-LABEL: define {{[^@]+}}@bar
+// CHECK-SAME: (i16 noundef [[I:%.*]], i16 noundef [[J:%.*]]) addrspace(1) 
#[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[I_ADDR:%.*]] = alloca i16, align 1
+// CHECK-NEXT:[[J_ADDR:%.*]] = alloca i16, align 1
+// CHECK-NEXT:store i16 [[I]], ptr [[I_ADDR]], align 1
+// CHECK-NEXT:store i16 [[J]], ptr [[J_ADDR]], align 1
+// CHECK-NEXT:[[TMP0:%.*]] = load i16, ptr [[I_ADDR]], align 1
+// CHECK-NEXT:[[TMP1:%.*]] = load i16, ptr [[J_ADDR]], align 1
+// CHECK-NEXT:[[CALL:%.*]] = call addrspace(1) i16 @g(i16 noundef 
[[TMP0]], i16 noundef [[TMP1]])
+// CHECK-NEXT:ret i16 [[CALL]]
+//
+int bar(int i, int j) {
+  return g(i, j);
+}
+
+// CHECK-LABEL: define {{[^@]+}}@foo
+// CHECK-SAME: (i16 noundef [[I:%.*]]) addrspace(1) #[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[I_ADDR:%.*]] = alloca i16, align 1
+// CHECK-NEXT:store i16 [[I]], ptr [[I_ADDR]], align 1
+// CHECK-NEXT:[[TMP0:%.*]] = load i16, ptr [[I_ADDR]], align 1
+// CHECK-NEXT:[[CALL:%.*]] = call addrspace(1) i16 @g(i16 noundef [[TMP0]])
+// CHECK-NEXT:ret i16 [[CALL]]
+//
+int foo(int i) {
+  return g(i);
+}
+
+// CHECK-LABEL: define {{[^@]+}}@g
+// CHECK-SAME: (i16 noundef [[X:%.*]], i16 noundef [[Y:%.*]]) addrspace(1) 
#[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[X_ADDR:%.*]] = alloca i16, align 1
+// CHECK-NEXT:[[Y_ADDR:%.*]] = alloca i16, align 1
+// CHECK-NEXT:store i16 [[X]], ptr [[X_ADDR]], align 1
+// CHECK-NEXT:store i16 [[Y]], ptr [[Y_ADDR]], align 1
+// CHECK-NEXT:[[TMP0:%.*]] = load i16, ptr [[X_ADDR]], align 1
+// CHECK-NEXT:[[TMP1:%.*]] = load i16, ptr [[Y_ADDR]], align 1
+// CHECK-NEXT:[[ADD:%.*]] = add nsw i16 [[TMP0]], [[TMP1]]
+// CHECK-NEXT:ret i16 [[ADD]]
+//
+int g(int x, int y) {
+  return x + y;
+}



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


[clang] 7191232 - clang: Fix another assert from not respecting function address spaces

2022-12-21 Thread Matt Arsenault via cfe-commits

Author: Matt Arsenault
Date: 2022-12-21T08:27:24-05:00
New Revision: 719123230577ebfb689b53ed09f4d06ddc1664ef

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

LOG: clang: Fix another assert from not respecting function address spaces

Added: 
clang/test/CodeGen/incomplete-function-type-function-addrspace.c

Modified: 
clang/lib/CodeGen/CodeGenModule.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 50e2f5bf212e..ac71346de298 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -4120,8 +4120,8 @@ llvm::Constant *CodeGenModule::GetOrCreateLLVMFunction(
 return F;
   }
 
-  llvm::Type *PTy = llvm::PointerType::getUnqual(Ty);
-  return llvm::ConstantExpr::getBitCast(F, PTy);
+  return llvm::ConstantExpr::getBitCast(F,
+
Ty->getPointerTo(F->getAddressSpace()));
 }
 
 /// GetAddrOfFunction - Return the address of the given function.  If Ty is

diff  --git a/clang/test/CodeGen/incomplete-function-type-function-addrspace.c 
b/clang/test/CodeGen/incomplete-function-type-function-addrspace.c
new file mode 100644
index ..cce6059d7fe1
--- /dev/null
+++ b/clang/test/CodeGen/incomplete-function-type-function-addrspace.c
@@ -0,0 +1,37 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --function-signature
+// REQUIRES: avr-registered-target
+// RUN: %clang_cc1 -triple avr-- -emit-llvm -o - %s | FileCheck %s
+
+// Copy of incomplete-function-type-2.c run with AVR.
+
+// Make sure the address space of the function is respected for incomplete
+// functions.
+
+struct test10_B;
+typedef struct test10_B test10_F3(double);
+void test10_foo(test10_F3 p1);
+struct test10_B test10_b(double);
+// CHECK-LABEL: define {{[^@]+}}@test10_bar
+// CHECK-SAME: () addrspace(1) #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:call addrspace(1) void @test10_foo(ptr addrspace(1) noundef 
@test10_b)
+// CHECK-NEXT:ret void
+//
+void test10_bar(void) {
+  test10_foo(test10_b);
+}
+struct test10_B {};
+// CHECK-LABEL: define {{[^@]+}}@test10_foo
+// CHECK-SAME: (ptr addrspace(1) noundef [[P1:%.*]]) addrspace(1) #[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[P1_ADDR:%.*]] = alloca ptr addrspace(1), align 1
+// CHECK-NEXT:[[AGG_TMP:%.*]] = alloca [[STRUCT_TEST10_B:%.*]], align 1
+// CHECK-NEXT:store ptr addrspace(1) [[P1]], ptr [[P1_ADDR]], align 1
+// CHECK-NEXT:[[TMP0:%.*]] = load ptr addrspace(1), ptr [[P1_ADDR]], align 
1
+// CHECK-NEXT:[[CALL:%.*]] = call addrspace(1) [[STRUCT_TEST10_B]] 
[[TMP0]](float noundef 0.00e+00)
+// CHECK-NEXT:ret void
+//
+void test10_foo(test10_F3 p1)
+{
+  p1(0.0);
+}



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


[clang] 2bb5954 - clang: Respect function address space for __builtin_function_start

2022-12-21 Thread Matt Arsenault via cfe-commits

Author: Matt Arsenault
Date: 2022-12-21T08:27:24-05:00
New Revision: 2bb59549e11fdb1d6b6c4e68f4572783f414d67f

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

LOG: clang: Respect function address space for __builtin_function_start

Fixes assertion.

Added: 
clang/test/CodeGen/avr/builtin-function-start.c

Modified: 
clang/lib/CodeGen/CodeGenModule.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index ac71346de2987..fcb60e3b4e705 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -4170,8 +4170,9 @@ llvm::Constant *CodeGenModule::GetFunctionStart(const 
ValueDecl *Decl) {
   llvm::GlobalValue *F =
   cast(GetAddrOfFunction(Decl)->stripPointerCasts());
 
-  return llvm::ConstantExpr::getBitCast(llvm::NoCFIValue::get(F),
-llvm::Type::getInt8PtrTy(VMContext));
+  return llvm::ConstantExpr::getBitCast(
+  llvm::NoCFIValue::get(F),
+  llvm::Type::getInt8PtrTy(VMContext, F->getAddressSpace()));
 }
 
 static const FunctionDecl *

diff  --git a/clang/test/CodeGen/avr/builtin-function-start.c 
b/clang/test/CodeGen/avr/builtin-function-start.c
new file mode 100644
index 0..293c8061299d7
--- /dev/null
+++ b/clang/test/CodeGen/avr/builtin-function-start.c
@@ -0,0 +1,13 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --function-signature --check-globals
+// RUN: %clang_cc1 -triple avr-- -emit-llvm -o - %s | FileCheck %s
+
+//.
+// CHECK: @e = global ptr addrspacecast (ptr addrspace(1) no_cfi @a to ptr), 
align 1
+//.
+// CHECK-LABEL: define {{[^@]+}}@a
+// CHECK-SAME: () addrspace(1) #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret void
+//
+void a(void) {}
+const void *e = __builtin_function_start(a);



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


[PATCH] D138253: [-Wunsafe-buffer-usage] NFC: Implement fix-strategies and variable-use-claiming.

2022-12-21 Thread Mikael Holmén via Phabricator via cfe-commits
uabelho added a comment.

It crashes on this as well:

  void f(int a[])
  {
  int b = {a[1]};
  }

with

  clang -cc1 foo.c -Weverything

I get

  clang: ../../clang/lib/Analysis/UnsafeBufferUsage.cpp:233: void (anonymous 
namespace)::DeclUseTracker::claimUse(const clang::DeclRefExpr *): Assertion 
`Uses->count(DRE) && "DRE not found or claimed by multiple matchers!"' failed.

But now I will indeed add -Wno-unsafe-buffer-usage. :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138253

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


[PATCH] D140475: BEGIN_PUBLIC test phabricator

2022-12-21 Thread Dani Ferreira Franco Moura via Phabricator via cfe-commits
merrymeerkat created this revision.
Herald added a reviewer: NoQ.
Herald added a project: All.
merrymeerkat requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

END_PUBLIC


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140475

Files:
  clang/include/clang/Analysis/AnalysisDiagnostic.h


Index: clang/include/clang/Analysis/AnalysisDiagnostic.h
===
--- clang/include/clang/Analysis/AnalysisDiagnostic.h
+++ clang/include/clang/Analysis/AnalysisDiagnostic.h
@@ -9,6 +9,8 @@
 #ifndef LLVM_CLANG_ANALYSIS_ANALYSISDIAGNOSTIC_H
 #define LLVM_CLANG_ANALYSIS_ANALYSISDIAGNOSTIC_H
 
+// why am i here
+//
 #include "clang/Basic/DiagnosticAnalysis.h"
 
 #endif


Index: clang/include/clang/Analysis/AnalysisDiagnostic.h
===
--- clang/include/clang/Analysis/AnalysisDiagnostic.h
+++ clang/include/clang/Analysis/AnalysisDiagnostic.h
@@ -9,6 +9,8 @@
 #ifndef LLVM_CLANG_ANALYSIS_ANALYSISDIAGNOSTIC_H
 #define LLVM_CLANG_ANALYSIS_ANALYSISDIAGNOSTIC_H
 
+// why am i here
+//
 #include "clang/Basic/DiagnosticAnalysis.h"
 
 #endif
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D140475: BEGIN_PUBLIC test phabricator

2022-12-21 Thread Dani Ferreira Franco Moura via Phabricator via cfe-commits
merrymeerkat updated this revision to Diff 484554.
merrymeerkat added a comment.

?:


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140475

Files:
  clang/include/clang/Analysis/AnalysisDiagnostic.h


Index: clang/include/clang/Analysis/AnalysisDiagnostic.h
===
--- clang/include/clang/Analysis/AnalysisDiagnostic.h
+++ clang/include/clang/Analysis/AnalysisDiagnostic.h
@@ -9,6 +9,8 @@
 #ifndef LLVM_CLANG_ANALYSIS_ANALYSISDIAGNOSTIC_H
 #define LLVM_CLANG_ANALYSIS_ANALYSISDIAGNOSTIC_H
 
+// why am i here ??
+
 #include "clang/Basic/DiagnosticAnalysis.h"
 
 #endif


Index: clang/include/clang/Analysis/AnalysisDiagnostic.h
===
--- clang/include/clang/Analysis/AnalysisDiagnostic.h
+++ clang/include/clang/Analysis/AnalysisDiagnostic.h
@@ -9,6 +9,8 @@
 #ifndef LLVM_CLANG_ANALYSIS_ANALYSISDIAGNOSTIC_H
 #define LLVM_CLANG_ANALYSIS_ANALYSISDIAGNOSTIC_H
 
+// why am i here ??
+
 #include "clang/Basic/DiagnosticAnalysis.h"
 
 #endif
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D137517: [TargetParser] Generate the defs for RISCV CPUs using llvm-tblgen.

2022-12-21 Thread Francesco Petrogalli via Phabricator via cfe-commits
fpetrogalli updated this revision to Diff 484561.
fpetrogalli added a comment.

There is no need to use `target_include_directories(LLVMRISCVDesc PRIVATE 
${LLVM_LIBRARY_DIR}/TargetParser/)` for components that are not related to the 
RISC-V target. Thank you @lenary for the suggestion!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137517

Files:
  clang/lib/Basic/Targets/RISCV.cpp
  clang/lib/Driver/CMakeLists.txt
  clang/lib/Driver/ToolChains/Arch/RISCV.cpp
  llvm/include/llvm/TargetParser/RISCVTargetParser.def
  llvm/include/llvm/TargetParser/RISCVTargetParser.h
  llvm/include/llvm/TargetParser/TargetParser.h
  llvm/lib/Target/AArch64/AsmParser/CMakeLists.txt
  llvm/lib/Target/RISCV/RISCV.td
  llvm/lib/Target/RISCV/RISCVISelLowering.h
  llvm/lib/TargetParser/CMakeLists.txt
  llvm/lib/TargetParser/RISCVTargetParser.cpp
  llvm/lib/TargetParser/TargetParser.cpp
  llvm/utils/TableGen/CMakeLists.txt
  llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
  llvm/utils/TableGen/TableGen.cpp
  llvm/utils/TableGen/TableGenBackends.h

Index: llvm/utils/TableGen/TableGenBackends.h
===
--- llvm/utils/TableGen/TableGenBackends.h
+++ llvm/utils/TableGen/TableGenBackends.h
@@ -94,7 +94,7 @@
 void EmitDirectivesDecl(RecordKeeper &RK, raw_ostream &OS);
 void EmitDirectivesImpl(RecordKeeper &RK, raw_ostream &OS);
 void EmitDXILOperation(RecordKeeper &RK, raw_ostream &OS);
-
+void EmitRISCVTargetDef(RecordKeeper &RK, raw_ostream &OS);
 } // End llvm namespace
 
 #endif
Index: llvm/utils/TableGen/TableGen.cpp
===
--- llvm/utils/TableGen/TableGen.cpp
+++ llvm/utils/TableGen/TableGen.cpp
@@ -58,6 +58,7 @@
   GenDirectivesEnumDecl,
   GenDirectivesEnumImpl,
   GenDXILOperation,
+  GenRISCVTargetDef,
 };
 
 namespace llvm {
@@ -141,8 +142,9 @@
 clEnumValN(GenDirectivesEnumImpl, "gen-directive-impl",
"Generate directive related implementation code"),
 clEnumValN(GenDXILOperation, "gen-dxil-operation",
-   "Generate DXIL operation information")));
-
+   "Generate DXIL operation information"),
+clEnumValN(GenRISCVTargetDef, "gen-riscv-target-def",
+   "Generate the list of CPU for RISCV")));
 cl::OptionCategory PrintEnumsCat("Options for -print-enums");
 cl::opt Class("class", cl::desc("Print Enum list for this class"),
cl::value_desc("class name"),
@@ -278,6 +280,9 @@
   case GenDXILOperation:
 EmitDXILOperation(Records, OS);
 break;
+  case GenRISCVTargetDef:
+EmitRISCVTargetDef(Records, OS);
+break;
   }
 
   return false;
Index: llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
===
--- /dev/null
+++ llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
@@ -0,0 +1,60 @@
+//===- RISCVTargetDefEmitter.cpp - Generate lists of RISCV CPUs ---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This tablegen backend emits the include file needed by the target
+// parser to parse the RISC-V CPUs.
+//
+//===--===//
+
+#include "llvm/TableGen/Record.h"
+#include 
+namespace llvm {
+
+std::string getEnumFeatures(Record &Rec) {
+  std::vector Features = Rec.getValueAsListOfDefs("Features");
+  if (std::find_if(Features.begin(), Features.end(), [](Record *R) {
+return R->getName() == "Feature64Bit";
+  }) != Features.end())
+return "FK_64BIT";
+
+  return "FK_NONE";
+}
+
+void EmitRISCVTargetDef(RecordKeeper &RK, raw_ostream &OS) {
+  const auto &Map = RK.getDefs();
+
+  OS << "#ifndef PROC\n"
+ << "#define PROC(ENUM, NAME, FEATURES, DEFAULT_MARCH)\n"
+ << "#endif\n\n";
+
+  OS << "PROC(INVALID, {\"invalid\"}, FK_INVALID, {\"\"})\n";
+  // Iterate on all definition records.
+  for (auto &Def : Map) {
+const auto &Record = Def.second;
+if (Record->isSubClassOf("RISCVProcessorModelPROC"))
+  OS << "PROC(" << Record->getName() << ", "
+ << "{\"" << Record->getValueAsString("Name") << "\"},"
+ << getEnumFeatures(*Record) << ", "
+ << "{\"" << Record->getValueAsString("DefaultMarch") << "\"})\n";
+  }
+  OS << "\n#undef PROC\n";
+  OS << "\n";
+  OS << "#ifndef TUNE_PROC\n"
+ << "#define TUNE_PROC(ENUM, NAME)\n"
+ << "#endif\n\n";
+  OS << "TUNE_PROC(GENERIC, \"generic\")\n";
+  for (auto &Def : Map) {
+const auto &Record = Def.second;
+if (Record->isSubClassOf("RISCVProcessorModelTUNE_PROC"))
+  OS << "TUNE_PROC(" << Record->getName() << ", "
+   

[PATCH] D137517: [TargetParser] Generate the defs for RISCV CPUs using llvm-tblgen.

2022-12-21 Thread Francesco Petrogalli via Phabricator via cfe-commits
fpetrogalli updated this revision to Diff 484563.
fpetrogalli added a comment.

NFC - I just restored an empty line to prevent modifying a file that is not 
being touched by the patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137517

Files:
  clang/lib/Basic/Targets/RISCV.cpp
  clang/lib/Driver/CMakeLists.txt
  clang/lib/Driver/ToolChains/Arch/RISCV.cpp
  llvm/include/llvm/TargetParser/RISCVTargetParser.def
  llvm/include/llvm/TargetParser/RISCVTargetParser.h
  llvm/include/llvm/TargetParser/TargetParser.h
  llvm/lib/Target/RISCV/RISCV.td
  llvm/lib/Target/RISCV/RISCVISelLowering.h
  llvm/lib/TargetParser/CMakeLists.txt
  llvm/lib/TargetParser/RISCVTargetParser.cpp
  llvm/lib/TargetParser/TargetParser.cpp
  llvm/utils/TableGen/CMakeLists.txt
  llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
  llvm/utils/TableGen/TableGen.cpp
  llvm/utils/TableGen/TableGenBackends.h

Index: llvm/utils/TableGen/TableGenBackends.h
===
--- llvm/utils/TableGen/TableGenBackends.h
+++ llvm/utils/TableGen/TableGenBackends.h
@@ -94,7 +94,7 @@
 void EmitDirectivesDecl(RecordKeeper &RK, raw_ostream &OS);
 void EmitDirectivesImpl(RecordKeeper &RK, raw_ostream &OS);
 void EmitDXILOperation(RecordKeeper &RK, raw_ostream &OS);
-
+void EmitRISCVTargetDef(RecordKeeper &RK, raw_ostream &OS);
 } // End llvm namespace
 
 #endif
Index: llvm/utils/TableGen/TableGen.cpp
===
--- llvm/utils/TableGen/TableGen.cpp
+++ llvm/utils/TableGen/TableGen.cpp
@@ -58,6 +58,7 @@
   GenDirectivesEnumDecl,
   GenDirectivesEnumImpl,
   GenDXILOperation,
+  GenRISCVTargetDef,
 };
 
 namespace llvm {
@@ -141,8 +142,9 @@
 clEnumValN(GenDirectivesEnumImpl, "gen-directive-impl",
"Generate directive related implementation code"),
 clEnumValN(GenDXILOperation, "gen-dxil-operation",
-   "Generate DXIL operation information")));
-
+   "Generate DXIL operation information"),
+clEnumValN(GenRISCVTargetDef, "gen-riscv-target-def",
+   "Generate the list of CPU for RISCV")));
 cl::OptionCategory PrintEnumsCat("Options for -print-enums");
 cl::opt Class("class", cl::desc("Print Enum list for this class"),
cl::value_desc("class name"),
@@ -278,6 +280,9 @@
   case GenDXILOperation:
 EmitDXILOperation(Records, OS);
 break;
+  case GenRISCVTargetDef:
+EmitRISCVTargetDef(Records, OS);
+break;
   }
 
   return false;
Index: llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
===
--- /dev/null
+++ llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
@@ -0,0 +1,60 @@
+//===- RISCVTargetDefEmitter.cpp - Generate lists of RISCV CPUs ---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This tablegen backend emits the include file needed by the target
+// parser to parse the RISC-V CPUs.
+//
+//===--===//
+
+#include "llvm/TableGen/Record.h"
+#include 
+namespace llvm {
+
+std::string getEnumFeatures(Record &Rec) {
+  std::vector Features = Rec.getValueAsListOfDefs("Features");
+  if (std::find_if(Features.begin(), Features.end(), [](Record *R) {
+return R->getName() == "Feature64Bit";
+  }) != Features.end())
+return "FK_64BIT";
+
+  return "FK_NONE";
+}
+
+void EmitRISCVTargetDef(RecordKeeper &RK, raw_ostream &OS) {
+  const auto &Map = RK.getDefs();
+
+  OS << "#ifndef PROC\n"
+ << "#define PROC(ENUM, NAME, FEATURES, DEFAULT_MARCH)\n"
+ << "#endif\n\n";
+
+  OS << "PROC(INVALID, {\"invalid\"}, FK_INVALID, {\"\"})\n";
+  // Iterate on all definition records.
+  for (auto &Def : Map) {
+const auto &Record = Def.second;
+if (Record->isSubClassOf("RISCVProcessorModelPROC"))
+  OS << "PROC(" << Record->getName() << ", "
+ << "{\"" << Record->getValueAsString("Name") << "\"},"
+ << getEnumFeatures(*Record) << ", "
+ << "{\"" << Record->getValueAsString("DefaultMarch") << "\"})\n";
+  }
+  OS << "\n#undef PROC\n";
+  OS << "\n";
+  OS << "#ifndef TUNE_PROC\n"
+ << "#define TUNE_PROC(ENUM, NAME)\n"
+ << "#endif\n\n";
+  OS << "TUNE_PROC(GENERIC, \"generic\")\n";
+  for (auto &Def : Map) {
+const auto &Record = Def.second;
+if (Record->isSubClassOf("RISCVProcessorModelTUNE_PROC"))
+  OS << "TUNE_PROC(" << Record->getName() << ", "
+ << "\"" << Record->getValueAsString("Name") << "\")\n";
+  }
+
+  OS << "\n#undef TUNE_PROC\n";
+}
+} // namespace llvm
Index: llvm/utils/TableGen/CMake

[PATCH] D137517: [TargetParser] Generate the defs for RISCV CPUs using llvm-tblgen.

2022-12-21 Thread Francesco Petrogalli via Phabricator via cfe-commits
fpetrogalli updated this revision to Diff 484564.
fpetrogalli added a comment.

Same NFC - restore an empty line change...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137517

Files:
  clang/lib/Basic/Targets/RISCV.cpp
  clang/lib/Driver/ToolChains/Arch/RISCV.cpp
  llvm/include/llvm/TargetParser/RISCVTargetParser.def
  llvm/include/llvm/TargetParser/RISCVTargetParser.h
  llvm/include/llvm/TargetParser/TargetParser.h
  llvm/lib/Target/RISCV/RISCV.td
  llvm/lib/Target/RISCV/RISCVISelLowering.h
  llvm/lib/TargetParser/CMakeLists.txt
  llvm/lib/TargetParser/RISCVTargetParser.cpp
  llvm/lib/TargetParser/TargetParser.cpp
  llvm/utils/TableGen/CMakeLists.txt
  llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
  llvm/utils/TableGen/TableGen.cpp
  llvm/utils/TableGen/TableGenBackends.h

Index: llvm/utils/TableGen/TableGenBackends.h
===
--- llvm/utils/TableGen/TableGenBackends.h
+++ llvm/utils/TableGen/TableGenBackends.h
@@ -94,7 +94,7 @@
 void EmitDirectivesDecl(RecordKeeper &RK, raw_ostream &OS);
 void EmitDirectivesImpl(RecordKeeper &RK, raw_ostream &OS);
 void EmitDXILOperation(RecordKeeper &RK, raw_ostream &OS);
-
+void EmitRISCVTargetDef(RecordKeeper &RK, raw_ostream &OS);
 } // End llvm namespace
 
 #endif
Index: llvm/utils/TableGen/TableGen.cpp
===
--- llvm/utils/TableGen/TableGen.cpp
+++ llvm/utils/TableGen/TableGen.cpp
@@ -58,6 +58,7 @@
   GenDirectivesEnumDecl,
   GenDirectivesEnumImpl,
   GenDXILOperation,
+  GenRISCVTargetDef,
 };
 
 namespace llvm {
@@ -141,8 +142,9 @@
 clEnumValN(GenDirectivesEnumImpl, "gen-directive-impl",
"Generate directive related implementation code"),
 clEnumValN(GenDXILOperation, "gen-dxil-operation",
-   "Generate DXIL operation information")));
-
+   "Generate DXIL operation information"),
+clEnumValN(GenRISCVTargetDef, "gen-riscv-target-def",
+   "Generate the list of CPU for RISCV")));
 cl::OptionCategory PrintEnumsCat("Options for -print-enums");
 cl::opt Class("class", cl::desc("Print Enum list for this class"),
cl::value_desc("class name"),
@@ -278,6 +280,9 @@
   case GenDXILOperation:
 EmitDXILOperation(Records, OS);
 break;
+  case GenRISCVTargetDef:
+EmitRISCVTargetDef(Records, OS);
+break;
   }
 
   return false;
Index: llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
===
--- /dev/null
+++ llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
@@ -0,0 +1,60 @@
+//===- RISCVTargetDefEmitter.cpp - Generate lists of RISCV CPUs ---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This tablegen backend emits the include file needed by the target
+// parser to parse the RISC-V CPUs.
+//
+//===--===//
+
+#include "llvm/TableGen/Record.h"
+#include 
+namespace llvm {
+
+std::string getEnumFeatures(Record &Rec) {
+  std::vector Features = Rec.getValueAsListOfDefs("Features");
+  if (std::find_if(Features.begin(), Features.end(), [](Record *R) {
+return R->getName() == "Feature64Bit";
+  }) != Features.end())
+return "FK_64BIT";
+
+  return "FK_NONE";
+}
+
+void EmitRISCVTargetDef(RecordKeeper &RK, raw_ostream &OS) {
+  const auto &Map = RK.getDefs();
+
+  OS << "#ifndef PROC\n"
+ << "#define PROC(ENUM, NAME, FEATURES, DEFAULT_MARCH)\n"
+ << "#endif\n\n";
+
+  OS << "PROC(INVALID, {\"invalid\"}, FK_INVALID, {\"\"})\n";
+  // Iterate on all definition records.
+  for (auto &Def : Map) {
+const auto &Record = Def.second;
+if (Record->isSubClassOf("RISCVProcessorModelPROC"))
+  OS << "PROC(" << Record->getName() << ", "
+ << "{\"" << Record->getValueAsString("Name") << "\"},"
+ << getEnumFeatures(*Record) << ", "
+ << "{\"" << Record->getValueAsString("DefaultMarch") << "\"})\n";
+  }
+  OS << "\n#undef PROC\n";
+  OS << "\n";
+  OS << "#ifndef TUNE_PROC\n"
+ << "#define TUNE_PROC(ENUM, NAME)\n"
+ << "#endif\n\n";
+  OS << "TUNE_PROC(GENERIC, \"generic\")\n";
+  for (auto &Def : Map) {
+const auto &Record = Def.second;
+if (Record->isSubClassOf("RISCVProcessorModelTUNE_PROC"))
+  OS << "TUNE_PROC(" << Record->getName() << ", "
+ << "\"" << Record->getValueAsString("Name") << "\")\n";
+  }
+
+  OS << "\n#undef TUNE_PROC\n";
+}
+} // namespace llvm
Index: llvm/utils/TableGen/CMakeLists.txt
===
--- llvm/utils/Tab

[PATCH] D140467: [X86][Reduce] Preserve fast math flags when change it. NFCI

2022-12-21 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei added a comment.

> If it exists it must be tested.
> Every piece of code generation needs to be tested.

Let me show you the number:

  $ grep -rho '__builtin_ia32\w\+' clang/test/CodeGen | sort|uniq |wc -l
  337
  $ grep -rho '_mm512_\w\+' clang/test/CodeGen | sort|uniq |wc -l
  2304

Note most of `__builtin_ia32` tests are negative ones and `_mm512_` is less 
than 1/3 of the total x86 intrinsics. Two orders of magnitude!

I took a look at the tests. The positive tests come from 
clang/test/CodeGen/builtins-x86.c. Other targets don't have a big test either
`wc -l clang/test/CodeGen/builtins-*`

> These are not testing use of these builtins correctly

As I have explained, users are not suggested to use these builtins given we 
have provided the more stable, well documented corresponding intrinsics. The 
only case user has to use it is the intrinsic is missing. In that case, we do 
need test case for it.

In a word, as titled, it is NFC from the perspective of intrinsics. So I think 
we don't need test cases for them.

> This test amounts to a builtin header test for immintrin.h. This should move 
> to clang/test/Headers and replaced with a builtin test directly checking the 
> builtin handling

Not get your point. But currently no builtin tests under `clang/test/Headers/`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140467

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


[PATCH] D140467: [X86][Reduce] Preserve fast math flags when change it. NFCI

2022-12-21 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri requested changes to this revision.
lebedev.ri added a comment.

In D140467#4010675 , @pengfei wrote:

>> If it exists it must be tested.
>> Every piece of code generation needs to be tested.
>
> Let me show you the number:
>
>   $ grep -rho '__builtin_ia32\w\+' clang/test/CodeGen | sort|uniq |wc -l
>   337
>   $ grep -rho '_mm512_\w\+' clang/test/CodeGen | sort|uniq |wc -l
>   2304
>
> Note most of `__builtin_ia32` tests are negative ones and `_mm512_` is less 
> than 1/3 of the total x86 intrinsics. Two orders of magnitude!
>
> I took a look at the tests. The positive tests come from 
> clang/test/CodeGen/builtins-x86.c. Other targets don't have a big test either
> `wc -l clang/test/CodeGen/builtins-*`
>
>> These are not testing use of these builtins correctly
>
> As I have explained, users are not suggested to use these builtins given we 
> have provided the more stable, well documented corresponding intrinsics. The 
> only case user has to use it is the intrinsic is missing. In that case, we do 
> need test case for it.
>
> In a word, as titled, it is NFC from the perspective of intrinsics. So I 
> think we don't need test cases for them.
>
>> This test amounts to a builtin header test for immintrin.h. This should move 
>> to clang/test/Headers and replaced with a builtin test directly checking the 
>> builtin handling
>
> Not get your point. But currently no builtin tests under 
> `clang/test/Headers/`.

I agree with @arsenm. At least for clang irgen, we should have good test 
coverage.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140467

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


[PATCH] D139266: Headers: tweak inclusion condition for stdatomic.h

2022-12-21 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

We think this is incorrect, see comments here: 
https://boringssl-review.googlesource.com/c/boringssl/+/55845/3/crypto/refcount_c11.c#18


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139266

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


[PATCH] D139266: Headers: tweak inclusion condition for stdatomic.h

2022-12-21 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

(and https://bugs.chromium.org/p/chromium/issues/detail?id=1402885#c3)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139266

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


[PATCH] D137107: Allow MS extension: support of constexpr with __declspec(dllimport).

2022-12-21 Thread Zahira Ammarguellat via Phabricator via cfe-commits
zahiraam marked 3 inline comments as done.
zahiraam added inline comments.



Comment at: clang/lib/CodeGen/CodeGenModule.cpp:5006
+if (NeedsGlobalCtor || NeedsGlobalDtor)
+  DelayedCXXInitPosition[D] = ~0U;
+  } else {

efriedma wrote:
> zahiraam wrote:
> > Do you agree this should be done only when one of those flags is on?
> Yes, that's fine; I wasn't really paying close attention to the exact code.  
> Just wanted to make the point about the structure of the if statements, and 
> code was the easiest way to explain it.
> 
> Maybe the outer if statement should actually be `if (isStaticInit(D, 
> getLangOpts()) && NeedsGlobalCtor) {`.
> 
> On a related note, we might want to avoid the name "ctor", in case that 
> accidentally conflicts with some user code; an "__"-prefixed name would be 
> appropriate.
>> Maybe the outer if statement should actually be if (isStaticInit(D, 
>> getLangOpts()) && NeedsGlobalCtor) {
Not sure about that! There are cases where (isStaticInit(D, getLangOpts())) = 
true and NeedsGlobalCtor=false, but NeedsGlobalDtor=true. In which case a 
__dtor needs to be emitted, no?

Writing the condition as you are proposing would actually not get me into the 
body to emit the __dtor. Is that what we want?


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

https://reviews.llvm.org/D137107

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


[PATCH] D140467: [X86][Reduce] Preserve fast math flags when change it. NFCI

2022-12-21 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added a comment.

In D140467#4010675 , @pengfei wrote:

> As I have explained, users are not suggested to use these builtins given we 
> have provided the more stable, well documented corresponding intrinsics. The 
> only case user has to use it is the intrinsic is missing. In that case, we do 
> need test case for it.

Tests don't exist for users, they exist for compiler developers. We shouldn't 
have frail infrastructure that depends on people not using things that are 
available. I'm not asking to test every builtin in this change, but this does 
need a test that shows a case where fast math flags were incorrectly applied. 
The broader issue of missing builtin coverage is a separate problem.

> In a word, as titled, it is NFC from the perspective of intrinsics. So I 
> think we don't need test cases for them.

This is not NFC. This changes codegen.

>> This test amounts to a builtin header test for immintrin.h. This should move 
>> to clang/test/Headers and replaced with a builtin test directly checking the 
>> builtin handling
>
> Not get your point. But currently no builtin tests under 
> `clang/test/Headers/`.

These "builtin tests" are checking wrappers implemented in a builtin header, 
not builtins. These are two levels of functionality that should be 
independently tested


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140467

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


[PATCH] D140483: Remove empty header file.

2022-12-21 Thread Dani Ferreira Franco Moura via Phabricator via cfe-commits
merrymeerkat created this revision.
Herald added a reviewer: NoQ.
Herald added a project: All.
merrymeerkat 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/D140483

Files:
  clang/docs/tools/clang-formatted-files.txt
  clang/include/clang/Analysis/AnalysisDiagnostic.h
  clang/include/clang/module.modulemap


Index: clang/include/clang/module.modulemap
===
--- clang/include/clang/module.modulemap
+++ clang/include/clang/module.modulemap
@@ -94,7 +94,6 @@
   requires cplusplus
 
   module All { header "Basic/AllDiagnostics.h" export * }
-  module Analysis { header "Analysis/AnalysisDiagnostic.h" export * }
   module AST { header "AST/ASTDiagnostic.h" export * }
   module Comment { header "AST/CommentDiagnostic.h" export * }
   module Driver { header "Driver/DriverDiagnostic.h" export * }
Index: clang/include/clang/Analysis/AnalysisDiagnostic.h
===
--- clang/include/clang/Analysis/AnalysisDiagnostic.h
+++ /dev/null
@@ -1,14 +0,0 @@
-//===--- DiagnosticAnalysis.h - Diagnostics for libanalysis -*- C++ 
-*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===--===//
-
-#ifndef LLVM_CLANG_ANALYSIS_ANALYSISDIAGNOSTIC_H
-#define LLVM_CLANG_ANALYSIS_ANALYSISDIAGNOSTIC_H
-
-#include "clang/Basic/DiagnosticAnalysis.h"
-
-#endif
Index: clang/docs/tools/clang-formatted-files.txt
===
--- clang/docs/tools/clang-formatted-files.txt
+++ clang/docs/tools/clang-formatted-files.txt
@@ -116,7 +116,6 @@
 clang/examples/Attribute/Attribute.cpp
 clang/examples/CallSuperAttribute/CallSuperAttrInfo.cpp
 clang/examples/PluginsOrder/PluginsOrder.cpp
-clang/include/clang/Analysis/AnalysisDiagnostic.h
 clang/include/clang/Analysis/BodyFarm.h
 clang/include/clang/Analysis/IssueHash.h
 clang/include/clang/Analysis/MacroExpansionContext.h


Index: clang/include/clang/module.modulemap
===
--- clang/include/clang/module.modulemap
+++ clang/include/clang/module.modulemap
@@ -94,7 +94,6 @@
   requires cplusplus
 
   module All { header "Basic/AllDiagnostics.h" export * }
-  module Analysis { header "Analysis/AnalysisDiagnostic.h" export * }
   module AST { header "AST/ASTDiagnostic.h" export * }
   module Comment { header "AST/CommentDiagnostic.h" export * }
   module Driver { header "Driver/DriverDiagnostic.h" export * }
Index: clang/include/clang/Analysis/AnalysisDiagnostic.h
===
--- clang/include/clang/Analysis/AnalysisDiagnostic.h
+++ /dev/null
@@ -1,14 +0,0 @@
-//===--- DiagnosticAnalysis.h - Diagnostics for libanalysis -*- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===--===//
-
-#ifndef LLVM_CLANG_ANALYSIS_ANALYSISDIAGNOSTIC_H
-#define LLVM_CLANG_ANALYSIS_ANALYSISDIAGNOSTIC_H
-
-#include "clang/Basic/DiagnosticAnalysis.h"
-
-#endif
Index: clang/docs/tools/clang-formatted-files.txt
===
--- clang/docs/tools/clang-formatted-files.txt
+++ clang/docs/tools/clang-formatted-files.txt
@@ -116,7 +116,6 @@
 clang/examples/Attribute/Attribute.cpp
 clang/examples/CallSuperAttribute/CallSuperAttrInfo.cpp
 clang/examples/PluginsOrder/PluginsOrder.cpp
-clang/include/clang/Analysis/AnalysisDiagnostic.h
 clang/include/clang/Analysis/BodyFarm.h
 clang/include/clang/Analysis/IssueHash.h
 clang/include/clang/Analysis/MacroExpansionContext.h
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D139266: Headers: tweak inclusion condition for stdatomic.h

2022-12-21 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd added a comment.

@thakis and https://github.com/llvm/llvm-project/issues/59640


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139266

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


[PATCH] D140433: [Clang] Add `nvptx-arch` tool to query installed NVIDIA GPUs

2022-12-21 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 added inline comments.



Comment at: clang/tools/nvptx-arch/NVPTXArch.cpp:63
+
+printf("sm_%d%d\n", Major, Minor);
+  }

Do we want to include device number here?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140433

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


[PATCH] D140433: [Clang] Add `nvptx-arch` tool to query installed NVIDIA GPUs

2022-12-21 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added inline comments.



Comment at: clang/tools/nvptx-arch/NVPTXArch.cpp:63
+
+printf("sm_%d%d\n", Major, Minor);
+  }

tianshilei1992 wrote:
> Do we want to include device number here?
For `amdgpu-arch` and here we just have it implicitly in the order, so the n-th 
line is the n-th device, i.e.
```
sm_70 // device 0
sm_80 // device 1
sm_70 // device 2
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140433

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


[PATCH] D137517: [TargetParser] Generate the defs for RISCV CPUs using llvm-tblgen.

2022-12-21 Thread Sergei Barannikov via Phabricator via cfe-commits
barannikov88 added inline comments.



Comment at: llvm/lib/TargetParser/CMakeLists.txt:29
+# LLVMTargetParser. See https://stackoverflow.com/a/25681179
+target_include_directories(LLVMTargetParser PUBLIC 
$)

Will it work if RISC-V target is not compiled-in?
This does not strictly add a cyclic dependency, but it would still be nice to 
avoid dependency on higher-level components.
Is it possible / reasonable to extract the part of the RISCV.td that relates to 
this component and put it separate td file in this directory? Or is it tightly 
coupled with the rest of the target description?




Comment at: llvm/utils/TableGen/RISCVTargetDefEmitter.cpp:15
+#include "llvm/TableGen/Record.h"
+#include 
+namespace llvm {

 [[ 
https://llvm.org/docs/CodingStandards.html#include-iostream-is-forbidden | is 
forbidden ]] by the coding standards.




Comment at: llvm/utils/TableGen/RISCVTargetDefEmitter.cpp:16
+#include 
+namespace llvm {
+

This [[ 
https://llvm.org/docs/CodingStandards.html#use-namespace-qualifiers-to-implement-previously-declared-functions
 | should be ]] `using namespace llvm;`



Comment at: llvm/utils/TableGen/RISCVTargetDefEmitter.cpp:18
+
+std::string getEnumFeatures(Record &Rec) {
+  std::vector Features = Rec.getValueAsListOfDefs("Features");

This should be `static`.



Comment at: llvm/utils/TableGen/RISCVTargetDefEmitter.cpp:20
+  std::vector Features = Rec.getValueAsListOfDefs("Features");
+  if (std::find_if(Features.begin(), Features.end(), [](Record *R) {
+return R->getName() == "Feature64Bit";

(suggestion) LLVM's version of find_if accepts ranges, which is a bit shorter.



Comment at: llvm/utils/TableGen/RISCVTargetDefEmitter.cpp:28
+
+void EmitRISCVTargetDef(RecordKeeper &RK, raw_ostream &OS) {
+  const auto &Map = RK.getDefs();

This function does not seem to mutate RecordKeeper, so it should be `const`.



Comment at: llvm/utils/TableGen/RISCVTargetDefEmitter.cpp:37
+  // Iterate on all definition records.
+  for (auto &Def : Map) {
+const auto &Record = Def.second;

Should also `const`, same for the loop below.



Comment at: llvm/utils/TableGen/RISCVTargetDefEmitter.cpp:52
+  for (auto &Def : Map) {
+const auto &Record = Def.second;
+if (Record->isSubClassOf("RISCVProcessorModelTUNE_PROC"))

Same for the loop above.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137517

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


[PATCH] D127812: [AArch64] FMV support and necessary target features dependencies.

2022-12-21 Thread Pavel Iliin via Phabricator via cfe-commits
ilinpv added a comment.



In D127812#4009577 , @hctim wrote:

> In D127812#4009447 , @hctim wrote:
>
>> Hi, this looks like a candidate for breaking the MSan bot: 
>> https://lab.llvm.org/buildbot/#/builders/5/builds/30139
>>
>> Still looking into it and bisecting, will let you know when I have more 
>> info. To reproduce the bots, the best way (because MSan setup is tricky 
>> because it requires an instrumented libcxx) is to use the scripts from 
>> https://github.com/google/sanitizers/wiki/SanitizerBotReproduceBuild 
>> (buildbot_fast.sh is the right one).
>
> Yeah, unfortunately I did track this failure down to this commit and reverted 
> it upstream. If you need help figuring it out, please let me know. You may 
> find that adding `-fsanitize-memory-track-origins=2` useful to add to the 
> buildscript as well (which can be done by changing `check_stage2_msan` to 
> `check_stage2_msan_track_origins` in `buildbot_fast.sh`.

It would be great to have more details how to setup up your bot, using 
buildbot_fast.sh on x86_64 Ubuntu 22.04 LTS leads to error ( pthreads installed 
):

  CMake Error at 
/usr/share/cmake-3.22/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
Could NOT find Threads (missing: Threads_FOUND)
  Call Stack (most recent call first):
/usr/share/cmake-3.22/Modules/FindPackageHandleStandardArgs.cmake:594 
(_FPHSA_FAILURE_MESSAGE)
/usr/share/cmake-3.22/Modules/FindThreads.cmake:238 
(FIND_PACKAGE_HANDLE_STANDARD_ARGS)
cmake/config-ix.cmake:114 (find_package)
CMakeLists.txt:776 (include)

Also MemorySanitizer: use-of-uninitialized-value cases from 
https://lab.llvm.org/buildbot/#/builders/5/builds/30139 looks fine locally, all 
values initialized, could MSAN produce false positive results?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127812

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


[PATCH] D140327: [clang] Remove overly restrictive aggregate paren init logic

2022-12-21 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov accepted this revision.
ilya-biryukov added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140327

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


[clang] c77a91b - [clang] Remove overly restrictive aggregate paren init logic

2022-12-21 Thread Alan Zhao via cfe-commits

Author: Alan Zhao
Date: 2022-12-21T08:21:05-08:00
New Revision: c77a91bb7ba793ec3a6a5da3743ed55056291658

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

LOG: [clang] Remove overly restrictive aggregate paren init logic

Previously, we would only attempt to perform a parenthesized aggregate
initialization if constructor initialization failed for only the default
constructor, default copy constructor, and default move constructor. The
original intent of this logic was to reject initializing objects that
have failed resolving a user-defined constructor. However, this check is
redundant because we check for isAggregate() before attempting to
perform a parenthesized aggregate initialization, and classes that have
user-defined or user-declared constructors are not aggregates.
Furthermore, this check is too restrictive - the following valid
examples fail:
* Aggregate class with user-defined destructor - fails because default
  move constructors are not generated for classes with user-defined
  destructors
  (https://github.com/llvm/llvm-project/issues/54040#issuecomment-1356926048)
* Concept-guarded conversion operator on an aggregate's member:
  (https://github.com/llvm/llvm-project/issues/54040#issuecomment-1356931745)

The solution therefore is to remove this logic; existing tests still
pass, and the previously failing examples now compile.

Reviewed By: ilya-biryukov

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

Added: 


Modified: 
clang/lib/Sema/SemaInit.cpp
clang/test/CodeGen/paren-list-agg-init.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index de419cae490ff..103986521f76e 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -5930,25 +5930,6 @@ static bool canPerformArrayCopy(const InitializedEntity 
&Entity) {
   return false;
 }
 
-static bool onlyHasDefaultedCtors(OverloadCandidateSet &OCS) {
-  if (OCS.size() != 3)
-return false;
-
-  bool HasDefaultCtor = false, HasCopyCtor = false, HasMoveCtor = false;
-  for (const auto &Candidate : OCS) {
-if (auto *Ctor = dyn_cast_or_null(Candidate.Function);
-Ctor != nullptr && Ctor->isDefaulted()) {
-  if (Ctor->isDefaultConstructor())
-HasDefaultCtor = true;
-  else if (Ctor->isCopyConstructor())
-HasCopyCtor = true;
-  else if (Ctor->isMoveConstructor())
-HasMoveCtor = true;
-}
-  }
-  return HasDefaultCtor && HasCopyCtor && HasMoveCtor;
-}
-
 void InitializationSequence::InitializeFrom(Sema &S,
 const InitializedEntity &Entity,
 const InitializationKind &Kind,
@@ -6196,8 +6177,7 @@ void InitializationSequence::InitializeFrom(Sema &S,
   if (const auto *RD =
   
dyn_cast(DestType->getAs()->getDecl());
   S.getLangOpts().CPlusPlus20 && RD && RD->isAggregate() && Failed() &&
-  getFailureKind() == FK_ConstructorOverloadFailed &&
-  onlyHasDefaultedCtors(getFailedCandidateSet())) {
+  getFailureKind() == FK_ConstructorOverloadFailed) {
 // C++20 [dcl.init] 17.6.2.2:
 //   - Otherwise, if no constructor is viable, the destination type is
 //   an

diff  --git a/clang/test/CodeGen/paren-list-agg-init.cpp 
b/clang/test/CodeGen/paren-list-agg-init.cpp
index 991cb4950b187..a7534fb907d2b 100644
--- a/clang/test/CodeGen/paren-list-agg-init.cpp
+++ b/clang/test/CodeGen/paren-list-agg-init.cpp
@@ -1,9 +1,25 @@
 // RUN: %clang_cc1 -std=c++20 %s -emit-llvm -triple x86_64-unknown-linux-gnu 
-o - | FileCheck %s
 
+template 
+struct IsChar {
+  constexpr operator bool() const { return false; }
+};
+
+template<>
+struct IsChar {
+  constexpr operator bool() const { return true; }
+};
+
+template 
+concept SameAsChar = (bool)IsInt();
+
 // CHECK-DAG: [[STRUCT_A:%.*]] = type { i8, double }
 struct A {
   char i;
   double j;
+
+  template 
+  operator T() const { return i; };
 };
 
 // CHECK-DAG: [[STRUCT_B:%.*]] = type { [[STRUCT_A]], i32 }
@@ -29,6 +45,7 @@ struct D {
 struct E {
   int a;
   const char* fn = __builtin_FUNCTION();
+  ~E() {};
 };
 
 // CHECK-DAG: [[STRUCT_F:%.*]] = type { i8 }



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


[PATCH] D140327: [clang] Remove overly restrictive aggregate paren init logic

2022-12-21 Thread Alan Zhao via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc77a91bb7ba7: [clang] Remove overly restrictive aggregate 
paren init logic (authored by ayzhao).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140327

Files:
  clang/lib/Sema/SemaInit.cpp
  clang/test/CodeGen/paren-list-agg-init.cpp


Index: clang/test/CodeGen/paren-list-agg-init.cpp
===
--- clang/test/CodeGen/paren-list-agg-init.cpp
+++ clang/test/CodeGen/paren-list-agg-init.cpp
@@ -1,9 +1,25 @@
 // RUN: %clang_cc1 -std=c++20 %s -emit-llvm -triple x86_64-unknown-linux-gnu 
-o - | FileCheck %s
 
+template 
+struct IsChar {
+  constexpr operator bool() const { return false; }
+};
+
+template<>
+struct IsChar {
+  constexpr operator bool() const { return true; }
+};
+
+template 
+concept SameAsChar = (bool)IsInt();
+
 // CHECK-DAG: [[STRUCT_A:%.*]] = type { i8, double }
 struct A {
   char i;
   double j;
+
+  template 
+  operator T() const { return i; };
 };
 
 // CHECK-DAG: [[STRUCT_B:%.*]] = type { [[STRUCT_A]], i32 }
@@ -29,6 +45,7 @@
 struct E {
   int a;
   const char* fn = __builtin_FUNCTION();
+  ~E() {};
 };
 
 // CHECK-DAG: [[STRUCT_F:%.*]] = type { i8 }
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -5930,25 +5930,6 @@
   return false;
 }
 
-static bool onlyHasDefaultedCtors(OverloadCandidateSet &OCS) {
-  if (OCS.size() != 3)
-return false;
-
-  bool HasDefaultCtor = false, HasCopyCtor = false, HasMoveCtor = false;
-  for (const auto &Candidate : OCS) {
-if (auto *Ctor = dyn_cast_or_null(Candidate.Function);
-Ctor != nullptr && Ctor->isDefaulted()) {
-  if (Ctor->isDefaultConstructor())
-HasDefaultCtor = true;
-  else if (Ctor->isCopyConstructor())
-HasCopyCtor = true;
-  else if (Ctor->isMoveConstructor())
-HasMoveCtor = true;
-}
-  }
-  return HasDefaultCtor && HasCopyCtor && HasMoveCtor;
-}
-
 void InitializationSequence::InitializeFrom(Sema &S,
 const InitializedEntity &Entity,
 const InitializationKind &Kind,
@@ -6196,8 +6177,7 @@
   if (const auto *RD =
   
dyn_cast(DestType->getAs()->getDecl());
   S.getLangOpts().CPlusPlus20 && RD && RD->isAggregate() && Failed() &&
-  getFailureKind() == FK_ConstructorOverloadFailed &&
-  onlyHasDefaultedCtors(getFailedCandidateSet())) {
+  getFailureKind() == FK_ConstructorOverloadFailed) {
 // C++20 [dcl.init] 17.6.2.2:
 //   - Otherwise, if no constructor is viable, the destination type is
 //   an


Index: clang/test/CodeGen/paren-list-agg-init.cpp
===
--- clang/test/CodeGen/paren-list-agg-init.cpp
+++ clang/test/CodeGen/paren-list-agg-init.cpp
@@ -1,9 +1,25 @@
 // RUN: %clang_cc1 -std=c++20 %s -emit-llvm -triple x86_64-unknown-linux-gnu -o - | FileCheck %s
 
+template 
+struct IsChar {
+  constexpr operator bool() const { return false; }
+};
+
+template<>
+struct IsChar {
+  constexpr operator bool() const { return true; }
+};
+
+template 
+concept SameAsChar = (bool)IsInt();
+
 // CHECK-DAG: [[STRUCT_A:%.*]] = type { i8, double }
 struct A {
   char i;
   double j;
+
+  template 
+  operator T() const { return i; };
 };
 
 // CHECK-DAG: [[STRUCT_B:%.*]] = type { [[STRUCT_A]], i32 }
@@ -29,6 +45,7 @@
 struct E {
   int a;
   const char* fn = __builtin_FUNCTION();
+  ~E() {};
 };
 
 // CHECK-DAG: [[STRUCT_F:%.*]] = type { i8 }
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -5930,25 +5930,6 @@
   return false;
 }
 
-static bool onlyHasDefaultedCtors(OverloadCandidateSet &OCS) {
-  if (OCS.size() != 3)
-return false;
-
-  bool HasDefaultCtor = false, HasCopyCtor = false, HasMoveCtor = false;
-  for (const auto &Candidate : OCS) {
-if (auto *Ctor = dyn_cast_or_null(Candidate.Function);
-Ctor != nullptr && Ctor->isDefaulted()) {
-  if (Ctor->isDefaultConstructor())
-HasDefaultCtor = true;
-  else if (Ctor->isCopyConstructor())
-HasCopyCtor = true;
-  else if (Ctor->isMoveConstructor())
-HasMoveCtor = true;
-}
-  }
-  return HasDefaultCtor && HasCopyCtor && HasMoveCtor;
-}
-
 void InitializationSequence::InitializeFrom(Sema &S,
 const InitializedEntity &Entity,
 const InitializationKind &Kind,
@@ -6196,8 +6177,7 @@
   if (const auto *RD =
   dyn_cast(DestType->getAs()->getDecl());
   S.getLangOpts().CPlusPlus20 && RD && RD->isAggrega

[PATCH] D140433: [Clang] Add `nvptx-arch` tool to query installed NVIDIA GPUs

2022-12-21 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 updated this revision to Diff 484594.
jhuber6 added a comment.

Change header I copied from the AMD implementation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140433

Files:
  clang/tools/CMakeLists.txt
  clang/tools/nvptx-arch/CMakeLists.txt
  clang/tools/nvptx-arch/NVPTXArch.cpp

Index: clang/tools/nvptx-arch/NVPTXArch.cpp
===
--- /dev/null
+++ clang/tools/nvptx-arch/NVPTXArch.cpp
@@ -0,0 +1,67 @@
+//===- NVPTXArch.cpp - list installed NVPTX devies --*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file implements a tool for detecting name of CUDA gpus installed in the
+// system.
+//
+//===--===//
+
+#if defined(__has_include)
+#if __has_include("cuda.h")
+#include "cuda.h"
+#define CUDA_HEADER_FOUND 1
+#else
+#define CUDA_HEADER_FOUND 0
+#endif
+#else
+#define CUDA_HEADER_FOUND 0
+#endif
+
+#if !CUDA_HEADER_FOUND
+int main() { return 1; }
+#else
+
+#include 
+#include 
+
+static int handleError(CUresult Err) {
+  const char *ErrStr = nullptr;
+  CUresult Result = cuGetErrorString(Err, &ErrStr);
+  if (Result != CUDA_SUCCESS)
+return 1;
+  printf("CUDA error: %s\n", ErrStr);
+  return 1;
+}
+
+int main() {
+  if (CUresult Err = cuInit(0))
+return 1;
+
+  int Count = 0;
+  if (cuDeviceGetCount(&Count))
+return 1;
+  if (Count == 0)
+return 0;
+  for (int DeviceId = 0; DeviceId < Count; ++DeviceId) {
+CUdevice Device;
+if (CUresult Err = cuDeviceGet(&Device, DeviceId))
+  return handleError(Err);
+
+int32_t Major, Minor;
+if (CUresult Err = cuDeviceGetAttribute(
+&Major, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR, Device))
+  return handleError(Err);
+if (CUresult Err = cuDeviceGetAttribute(
+&Minor, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR, Device))
+  return handleError(Err);
+
+printf("sm_%d%d\n", Major, Minor);
+  }
+  return 0;
+}
+#endif
Index: clang/tools/nvptx-arch/CMakeLists.txt
===
--- /dev/null
+++ clang/tools/nvptx-arch/CMakeLists.txt
@@ -0,0 +1,28 @@
+# //======//
+# //
+# // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+# // See https://llvm.org/LICENSE.txt for details.
+# // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+# //
+# //======//
+
+
+# TODO: This is deprecated. Since CMake 3.17 we can use FindCUDAToolkit instead.
+find_package(CUDA QUIET)
+find_library(cuda-library NAMES cuda PATHS /lib64)
+if (NOT cuda-library AND CUDA_FOUND)
+  get_filename_component(CUDA_LIBDIR "${CUDA_cudart_static_LIBRARY}" DIRECTORY)
+  find_library(cuda-library NAMES cuda HINTS "${CUDA_LIBDIR}/stubs")
+endif()
+
+if (NOT CUDA_FOUND OR NOT cuda-library)
+  message(STATUS "Not building nvptx-arch: cuda runtime not found")
+  return()
+endif()
+
+add_clang_tool(nvptx-arch NVPTXArch.cpp)
+
+set_target_properties(nvptx-arch PROPERTIES INSTALL_RPATH_USE_LINK_PATH ON)
+target_include_directories(nvptx-arch PRIVATE ${CUDA_INCLUDE_DIRS})
+
+clang_target_link_libraries(nvptx-arch PRIVATE ${cuda-library})
Index: clang/tools/CMakeLists.txt
===
--- clang/tools/CMakeLists.txt
+++ clang/tools/CMakeLists.txt
@@ -50,3 +50,4 @@
 add_clang_subdirectory(libclang)
 
 add_clang_subdirectory(amdgpu-arch)
+add_clang_subdirectory(nvptx-arch)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D105584: [MLIR][OpenMP] Distribute Construct Operation

2022-12-21 Thread Abid via Phabricator via cfe-commits
abidmalikwaterloo marked 5 inline comments as done.
abidmalikwaterloo added inline comments.



Comment at: mlir/test/Dialect/OpenMP/ops.mlir:124
 
+// CHECK-LABEL: omp_DistributeOp
+func.func @omp_DistributeOp(%lb : index, %ub : index, %step : index, %data_var 
: memref, %chunk_var : i32) -> () {

kiranchandramohan wrote:
> kiranchandramohan wrote:
> > Add a pretty-print test as well.
> Nit: please add a pretty-print test.
Just need clarification. Do you mean something similar to the following:

```
// CHECK-LABEL: omp_wsloop_pretty
func.func @omp_wsloop_pretty(%lb : index, %ub : index, %step : index, %data_var 
: memref, %linear_var : i32, %chunk_var : i32, %chunk_var2 : i16) -> () {

  // CHECK: omp.wsloop ordered(2)
  // CHECK-SAME: for (%{{.*}}) : index = (%{{.*}}) to (%{{.*}}) step (%{{.*}})
  omp.wsloop ordered(2)
  for (%iv) : index = (%lb) to (%ub) step (%step) {
omp.yield
  }

  // CHECK: omp.wsloop linear(%{{.*}} = %{{.*}} : memref) schedule(static)
  // CHECK-SAME: for (%{{.*}}) : index = (%{{.*}}) to (%{{.*}}) step (%{{.*}})
  omp.wsloop schedule(static) linear(%data_var = %linear_var : memref)
  for (%iv) : index = (%lb) to (%ub) step (%step) {
omp.yield
  }

  // CHECK: omp.wsloop linear(%{{.*}} = %{{.*}} : memref) schedule(static 
= %{{.*}} : i32) ordered(2)
  // CHECK-SAME: for (%{{.*}}) : index = (%{{.*}}) to (%{{.*}}) step (%{{.*}})
  omp.wsloop ordered(2) linear(%data_var = %linear_var : memref) 
schedule(static = %chunk_var : i32)
  for (%iv) : index = (%lb) to (%ub) step (%step) {
omp.yield
  }

  // CHECK: omp.wsloop linear(%{{.*}} = %{{.*}} : memref) schedule(dynamic 
= %{{.*}} : i32, nonmonotonic) ordered(2)
  // CHECK-SAME: for (%{{.*}}) : index = (%{{.*}}) to (%{{.*}}) step (%{{.*}})
  omp.wsloop ordered(2) linear(%data_var = %linear_var : memref) 
schedule(dynamic = %chunk_var : i32, nonmonotonic)
  for (%iv) : index = (%lb) to (%ub) step (%step)  {
omp.yield
  }

  // CHECK: omp.wsloop linear(%{{.*}} = %{{.*}} : memref) schedule(dynamic 
= %{{.*}} : i16, monotonic) ordered(2)
  // CHECK-SAME: for (%{{.*}}) : index = (%{{.*}}) to (%{{.*}}) step (%{{.*}})
  omp.wsloop ordered(2) linear(%data_var = %linear_var : memref) 
schedule(dynamic = %chunk_var2 : i16, monotonic)
  for (%iv) : index = (%lb) to (%ub) step (%step) {
omp.yield
  }

  // CHECK: omp.wsloop for (%{{.*}}) : index = (%{{.*}}) to (%{{.*}}) step 
(%{{.*}})
  omp.wsloop for (%iv) : index = (%lb) to (%ub) step (%step) {
omp.yield
  }

  // CHECK: omp.wsloop for (%{{.*}}) : index = (%{{.*}}) to (%{{.*}}) inclusive 
step (%{{.*}})
  omp.wsloop for (%iv) : index = (%lb) to (%ub) inclusive step (%step) {
omp.yield
  }

  // CHECK: omp.wsloop nowait
  // CHECK-SAME: for (%{{.*}}) : index = (%{{.*}}) to (%{{.*}}) step (%{{.*}})
  omp.wsloop nowait
  for (%iv) : index = (%lb) to (%ub) step (%step) {
omp.yield
  }

  // CHECK: omp.wsloop nowait order(concurrent)
  // CHECK-SAME: for (%{{.*}}) : index = (%{{.*}}) to (%{{.*}}) step (%{{.*}})
  omp.wsloop order(concurrent) nowait
  for (%iv) : index = (%lb) to (%ub) step (%step) {
omp.yield
  }

  return
}
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105584

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


[PATCH] D137817: [clangd] Improve action `RemoveUsingNamespace` for user-defined literals

2022-12-21 Thread Vincent Hong via Phabricator via cfe-commits
v1nh1shungry abandoned this revision.
v1nh1shungry added a comment.

Abandon because of the terrible implementation.

- The cost seems to be higher than the value.

- The place to insert isn't good enough.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137817

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


[PATCH] D139534: [analyzer] Don't escape local static memregions on bind

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

Finally, I had some time to come back to this.
Thanks for taking the time for such a detailed response, kudos! @NoQ

In D139534#3999455 , @NoQ wrote:

> Ok screw it, my static example is still broken. There's technically still a 
> leak in it because there's no time for the other code to kick in between `p = 
> (int *)malloc(sizeof(int));` and `p = 0;` to read the value from `p`.
>
> But in practice there could be a lot of things going on in between, that with 
> your patch might not trigger enough escapes. Let me disconnect from the 
> original test case and try to build a few examples more carefully.
>
>   void foo() {
> static int *p;
> escape(&p);
> p = malloc(sizeof(int));
> free_whatever_escaped();
> p = 0; // no-leak
>   }
>
> This isn't a leak, regardless of whether the variable is static or not. 
> Currently we display a leak when the variable is non-static (bad) but don't 
> display a leak when the variable is static (good). IIUC your patch might 
> break this. The important part is that in this case there's no direct 
> connection between the tracked pointer `p` and the escaped region `&p` 
> because `p` isn't stored in `&p` until the next line. So if you remove 
> invalidation of `p` on `free_whatever_escaped();`, it'll cause a new false 
> positive in the static case.

Yes, I'd introduce FP for this case.

>   void foo(cond) {
> static int *p;
> if (cond) {
>   p = malloc(sizeof(int));
>   free_whatever_escaped();
>   p = 0; // no-leak
> }
> escape(&p);
>   }
>
> In this case there's no leak as long as the first invocation of the function 
> always has `cond` set to false. In this case, again, there's no direct 
> connection between `&p` and the return value of `malloc()` when direct escape 
> of `&p` happens. On top of that, the direct escape of `&p` isn't observed at 
> all until much later in the analysis. But just because the local is static, 
> and the function can be called multiple times, the escape at the end of the 
> analysis may "affect" our decision-making at the beginning of the analysis. I 
> suspect your patch breaks this example as well.

Yes, we will report a FP there with my patch.

> So basically in order to do the right thing here, you need to make sure there 
> are no direct escapes of that static variable *anywhere* in the function. But 
> as long as there's no direct escapes, you're probably good to go. With 
> non-static locals you only need to observe escapes *before* the leak (but 
> possibly before the allocation as well), which we currently don't do a good 
> job at anyway.

I agree that we could improve escape handling of static variables by checking 
if that could have escaped *anywhere*. Although, I don't plan to invest time 
there.

> Then, again, it's possible that your patch improves FP rates than what we 
> currently have, just by being a different trade-off, given how artificial my 
> examples are, but we'll need some data to figure it out.

According to my differential analysis, I saw only 2 new issues and 1 
disappearing issue.
The test corpus includes roughly 170 projects, including really big ones; 
windows, Linux, old, new, C and C++ projects as well.
Also, note that we are not using the default set of checks, nor the cc1 driver.

The two new issues were both TPs, for memory leaks. I'll elaborate on these 
later.
I haven't investigated the single disappearing issue, which was about `The 
right operand of '<' is a garbage value`. In the context, I could see some 
local static variables though.

---

Here is the gist of one *new* TP:

  // OpenJDK src/java.base/unix/native/libjava/java_props_md.c
  #define NULL ((void*)0)
  typedef unsigned int uid_t;
  extern struct passwd *getpwuid(uid_t uid);
  extern uid_t getuid();
  extern char *strdup(const char *s);
  extern char *getenv(const char *name);
  struct passwd {
char *pw_dir;
  };
  
  typedef struct {
char *user_home;
  } java_props_t;
  
  java_props_t *GetJavaProperties(struct JNIEnv *env) {
static java_props_t sprops;
  
struct passwd *pwent = getpwuid(getuid());
sprops.user_home = pwent ? strdup(pwent->pw_dir) : NULL; // taking 'true' 
branch; allocating memory by 'strdup'
if (sprops.user_home == NULL || sprops.user_home[0] == '\0' ||
sprops.user_home[1] == '\0') {
  char *user_home = getenv("HOME");
  if ((user_home != NULL) && (user_home[0] != '\0'))
sprops.user_home = user_home; // leaking previous `sprops.user_home` !
}
  }

The other TP in the Samba project looks quite similar but involves a loop 
complicating things.

---

By looking at the results, I think my patch helps more than hinders, and I'm 
also not expecting many users severely impacted by this change.




Comment at: clang/test/Analysis/malloc-static-storage.cpp:33-38
+void malloc_escape() {
+  static int *p;
+  p = (int *)malloc(sizeof(int));
+  es

[PATCH] D139534: [analyzer] Don't escape local static memregions on bind

2022-12-21 Thread Balázs Benics via Phabricator via cfe-commits
steakhal updated this revision to Diff 484600.
steakhal added a comment.

- Add two test cases demonstrating the false-positives this patch will 
introduce. These are semantically equivalent to the one mentioned in the 
comments by @NoQ.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139534

Files:
  clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
  clang/test/Analysis/malloc-static-storage.cpp


Index: clang/test/Analysis/malloc-static-storage.cpp
===
--- /dev/null
+++ clang/test/Analysis/malloc-static-storage.cpp
@@ -0,0 +1,77 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,unix.Malloc -verify %s
+
+typedef __typeof(sizeof(int)) size_t;
+void* malloc(size_t size);
+void *calloc(size_t num, size_t size);
+void free(void * ptr);
+
+void escape(void *);
+void next_statement();
+
+void conditional_malloc(bool coin) {
+  static int *p;
+
+  if (coin) {
+p = (int *)malloc(sizeof(int));
+  }
+  p = 0; // Pointee of 'p' dies, which is recognized at the next statement.
+  next_statement(); // expected-warning {{Potential memory leak}}
+}
+
+void malloc_twice() {
+  static int *p;
+  p = (int *)malloc(sizeof(int));
+  next_statement();
+  p = (int *)malloc(sizeof(int));
+  next_statement(); // expected-warning {{Potential memory leak}}
+  p = 0;
+  next_statement(); // expected-warning {{Potential memory leak}}
+}
+
+void malloc_escape() {
+  static int *p;
+  p = (int *)malloc(sizeof(int));
+  escape(p); // no-leak
+  p = 0; // no-leak
+}
+
+void free_whatever_escaped();
+void malloc_escape_reversed() {
+  static int *p;
+  escape(&p);
+  p = (int *)malloc(sizeof(int));
+  free_whatever_escaped();
+  p = 0; // FIXME: We should not report a leak here.
+  next_statement(); // expected-warning {{Potential memory leak}}
+}
+
+int *malloc_return_static() {
+  static int *p = (int *)malloc(sizeof(int));
+  return p; // no-leak
+}
+
+int malloc_unreachable(int rng) {
+  // 'p' does not escape and never freed :(
+  static int *p;
+
+  // For the second invocation of this function, we leak the previous pointer.
+  // FIXME: We should catch this at some point.
+  p = (int *)malloc(sizeof(int));
+  *p = 0;
+
+  if (rng > 0)
+*p = rng;
+
+  return *p; // FIXME: We just leaked 'p'. We should warn about this.
+}
+
+void malloc_cond(bool cond) {
+  static int *p;
+  if (cond) {
+p = (int*)malloc(sizeof(int));
+free_whatever_escaped();
+p = 0; // FIXME: We should not report a leak here.
+next_statement(); // expected-warning {{Potential memory leak}}
+  }
+  escape(&p);
+}
Index: clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -3462,7 +3462,8 @@
   for (const std::pair &LocAndVal : LocAndVals) {
 // Cases (1) and (2).
 const MemRegion *MR = LocAndVal.first.getAsRegion();
-if (!MR || !MR->hasStackStorage()) {
+if (!MR ||
+!isa(MR->getMemorySpace())) 
{
   Escaped.push_back(LocAndVal.second);
   continue;
 }


Index: clang/test/Analysis/malloc-static-storage.cpp
===
--- /dev/null
+++ clang/test/Analysis/malloc-static-storage.cpp
@@ -0,0 +1,77 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,unix.Malloc -verify %s
+
+typedef __typeof(sizeof(int)) size_t;
+void* malloc(size_t size);
+void *calloc(size_t num, size_t size);
+void free(void * ptr);
+
+void escape(void *);
+void next_statement();
+
+void conditional_malloc(bool coin) {
+  static int *p;
+
+  if (coin) {
+p = (int *)malloc(sizeof(int));
+  }
+  p = 0; // Pointee of 'p' dies, which is recognized at the next statement.
+  next_statement(); // expected-warning {{Potential memory leak}}
+}
+
+void malloc_twice() {
+  static int *p;
+  p = (int *)malloc(sizeof(int));
+  next_statement();
+  p = (int *)malloc(sizeof(int));
+  next_statement(); // expected-warning {{Potential memory leak}}
+  p = 0;
+  next_statement(); // expected-warning {{Potential memory leak}}
+}
+
+void malloc_escape() {
+  static int *p;
+  p = (int *)malloc(sizeof(int));
+  escape(p); // no-leak
+  p = 0; // no-leak
+}
+
+void free_whatever_escaped();
+void malloc_escape_reversed() {
+  static int *p;
+  escape(&p);
+  p = (int *)malloc(sizeof(int));
+  free_whatever_escaped();
+  p = 0; // FIXME: We should not report a leak here.
+  next_statement(); // expected-warning {{Potential memory leak}}
+}
+
+int *malloc_return_static() {
+  static int *p = (int *)malloc(sizeof(int));
+  return p; // no-leak
+}
+
+int malloc_unreachable(int rng) {
+  // 'p' does not escape and never freed :(
+  static int *p;
+
+  // For the second invocation of this function, we leak the previous pointer.
+  // FIXME: We should catch this at some point.
+  p = (int *)malloc(sizeof(

[clang] d4959b5 - [Driver] Fix tests not to fail randomly on Windows

2022-12-21 Thread Paul Robinson via cfe-commits

Author: Paul Robinson
Date: 2022-12-21T09:37:12-08:00
New Revision: d4959b5a4bb888789f99a952a1304ce915dfee2f

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

LOG: [Driver] Fix tests not to fail randomly on Windows

These used a regex that didn't guard against backslashes, so
getting "lucky" with a temp dir name could make them fail.

Added: 


Modified: 
clang/test/Driver/freebsd.c
clang/test/Driver/fuchsia.c
clang/test/Driver/netbsd.c
clang/test/Driver/openbsd.c

Removed: 




diff  --git a/clang/test/Driver/freebsd.c b/clang/test/Driver/freebsd.c
index 87ce46d1c1c6e..a9afff22ae848 100644
--- a/clang/test/Driver/freebsd.c
+++ b/clang/test/Driver/freebsd.c
@@ -212,5 +212,5 @@
 // RELOCATABLE: "-r"
 // RELOCATABLE-NOT: "-dynamic-linker"
 // RELOCATABLE-NOT: "-l
-// RELOCATABLE-NOT: crt{{[^./]+}}.o
+// RELOCATABLE-NOT: crt{{[^./\\]+}}.o
 

diff  --git a/clang/test/Driver/fuchsia.c b/clang/test/Driver/fuchsia.c
index 339fd92309796..9c023329edb5f 100644
--- a/clang/test/Driver/fuchsia.c
+++ b/clang/test/Driver/fuchsia.c
@@ -89,7 +89,7 @@
 // CHECK-RELOCATABLE-NOT "-dynamic-linker"
 // CHECK-RELOCATABLE: "-r"
 // CHECK-RELOCATABLE-NOT: "-l
-// CHECK-RELOCATABLE-NOT: crt{{[^./]+}}.o
+// CHECK-RELOCATABLE-NOT: crt{{[^./\\]+}}.o
 
 // RUN: %clang -### %s --target=x86_64-unknown-fuchsia -nodefaultlibs 
-fuse-ld=lld 2>&1 \
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \

diff  --git a/clang/test/Driver/netbsd.c b/clang/test/Driver/netbsd.c
index 436772ab99795..52f3a33198059 100644
--- a/clang/test/Driver/netbsd.c
+++ b/clang/test/Driver/netbsd.c
@@ -476,4 +476,4 @@
 // RELOCATABLE-NOT: "-pie"
 // RELOCATABLE-NOT: "-dynamic-linker"
 // RELOCATABLE-NOT: "-l
-// RELOCATABLE-NOT: crt{{[^./]+}}.o
+// RELOCATABLE-NOT: crt{{[^./\\]+}}.o

diff  --git a/clang/test/Driver/openbsd.c b/clang/test/Driver/openbsd.c
index 3ba8a315f6e16..05d290a309c40 100644
--- a/clang/test/Driver/openbsd.c
+++ b/clang/test/Driver/openbsd.c
@@ -39,7 +39,7 @@
 // CHECK-LD-R: "-r"
 // CHECK-LD-R-NOT: "-dynamic-linker"
 // CHECK-LD-R-NOT: "-l
-// CHECK-LD-R-NOT: crt{{[^./]+}}.o
+// CHECK-LD-R-NOT: crt{{[^./\\]+}}.o
 // CHECK-LD-S: "-cc1" "-triple" "i686-pc-openbsd"
 // CHECK-LD-S: ld{{.*}}" "-e" "__start" "--eh-frame-hdr" "-Bdynamic" 
"-dynamic-linker" "{{.*}}ld.so" "-o" "a.out" "{{.*}}crt0.o" "{{.*}}crtbegin.o" 
"-L{{.*}}" "-s" "{{.*}}.o" "-lcompiler_rt" "-lc" "-lcompiler_rt" 
"{{.*}}crtend.o"
 // CHECK-LD-T: "-cc1" "-triple" "i686-pc-openbsd"



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


[PATCH] D137838: [Support] Move TargetParsers to new component

2022-12-21 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

This has introduced a circular dependency due to the forwarding header 
(forwarding header depends on new lib, new lib depends on support, where the 
forwarding header is). Generally this wouldn't be acceptable (& I'd suggest the 
patch be reverted on that basis) though I understand this is a complicated 
migration - what's the timeline for correcting this issue?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137838

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


[PATCH] D127812: [AArch64] FMV support and necessary target features dependencies.

2022-12-21 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added a comment.

In D127812#4010856 , @ilinpv wrote:

> It would be great to have more details how to setup up your bot, using 
> buildbot_fast.sh on x86_64 Ubuntu 22.04 LTS leads to error ( pthreads 
> installed ):
>
>   CMake Error at 
> /usr/share/cmake-3.22/Modules/FindPackageHandleStandardArgs.cmake:230 
> (message):
> Could NOT find Threads (missing: Threads_FOUND)
>   Call Stack (most recent call first):
> /usr/share/cmake-3.22/Modules/FindPackageHandleStandardArgs.cmake:594 
> (_FPHSA_FAILURE_MESSAGE)
> /usr/share/cmake-3.22/Modules/FindThreads.cmake:238 
> (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
> cmake/config-ix.cmake:114 (find_package)
> CMakeLists.txt:776 (include)
>
> Also MemorySanitizer: use-of-uninitialized-value cases from 
> https://lab.llvm.org/buildbot/#/builders/5/builds/30139 looks fine locally, 
> all values initialized, could MSAN produce false positive results?

MSan can find false positives, but that's only if code ends up in your binary 
that isn't built with MSan. The buildscripts are written so that everything 
gets instrumented.

Hmm, not exactly sure what's going on with the `could NOT find Threads` there. 
A quick googling seems to point to pthreads.so not being in the right places, 
but I don't think the buildbot does anything special. Do your regular builds 
with `-DLLVM_ENABLE_PROJECTS="compiler_rt;clang;lld"` work?

When you say that it looks fine locally, is that from your own checkout but 
using `-DLLVM_USE_SANITIZER=Memory`? First thing to check is that you do end up 
with MSan in the test (in particular the clang binary that's being produced), 
which you can do by `nm bin/clang-16 | grep __msan_init`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127812

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


[PATCH] D140432: [AArch64] Guard {vmull_p64, vmull_high_p64} with 'aes' target guard.

2022-12-21 Thread Mingming Liu via Phabricator via cfe-commits
mingmingl updated this revision to Diff 484608.
mingmingl added a comment.

update commit message to mention target guard 'aes' includes both FEAT_AES and 
FEAT_PMULL currently.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140432

Files:
  clang/include/clang/Basic/arm_neon.td
  clang/test/CodeGen/aarch64-poly128.c
  clang/test/Sema/aarch64-neon-target.c

Index: clang/test/Sema/aarch64-neon-target.c
===
--- clang/test/Sema/aarch64-neon-target.c
+++ clang/test/Sema/aarch64-neon-target.c
@@ -60,7 +60,7 @@
   vrnd32xq_f32(v4f32);
 }
 
-void undefined(uint32x2_t v2i32, uint32x4_t v4i32, uint16x8_t v8i16, uint8x16_t v16i8, uint8x8_t v8i8, float32x2_t v2f32, float32x4_t v4f32, float16x4_t v4f16, float64x2_t v2f64, bfloat16x4_t v4bf16, __bf16 bf16) {
+void undefined(uint32x2_t v2i32, uint32x4_t v4i32, uint16x8_t v8i16, uint8x16_t v16i8, uint8x8_t v8i8, float32x2_t v2f32, float32x4_t v4f32, float16x4_t v4f16, float64x2_t v2f64, bfloat16x4_t v4bf16, __bf16 bf16, poly64_t poly64, poly64x2_t poly64x2) {
   // dotprod
   vdot_u32(v2i32, v8i8, v8i8); // expected-error {{always_inline function 'vdot_u32' requires target feature 'dotprod'}}
   vdot_laneq_u32(v2i32, v8i8, v16i8, 1); // expected-error {{always_inline function 'vdot_u32' requires target feature 'dotprod'}}
@@ -92,4 +92,8 @@
   vcmlaq_rot270_laneq_f64(v2f64, v2f64, v2f64, 1); // expected-error {{always_inline function 'vcmlaq_rot270_f64' requires target feature 'v8.3a'}}
   // 8.5 - frint
   vrnd32xq_f32(v4f32); // expected-error {{always_inline function 'vrnd32xq_f32' requires target feature 'v8.5a'}}
+
+  vmull_p64(poly64, poly64);  // expected-error {{always_inline function 'vmull_p64' requires target feature 'aes'}}
+  vmull_high_p64(poly64x2, poly64x2);  // expected-error {{always_inline function 'vmull_high_p64' requires target feature 'aes'}}
+
 }
Index: clang/test/CodeGen/aarch64-poly128.c
===
--- clang/test/CodeGen/aarch64-poly128.c
+++ clang/test/CodeGen/aarch64-poly128.c
@@ -28,8 +28,8 @@
 // CHECK-LABEL: define {{[^@]+}}@test_vldrq_p128
 // CHECK-SAME: (ptr noundef [[PTR:%.*]]) #[[ATTR0]] {
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP2:%.*]] = load i128, ptr [[PTR]], align 16
-// CHECK-NEXT:ret i128 [[TMP2]]
+// CHECK-NEXT:[[TMP0:%.*]] = load i128, ptr [[PTR]], align 16
+// CHECK-NEXT:ret i128 [[TMP0]]
 //
 poly128_t test_vldrq_p128(poly128_t * ptr) {
   return vldrq_p128(ptr);
@@ -39,9 +39,9 @@
 // CHECK-LABEL: define {{[^@]+}}@test_ld_st_p128
 // CHECK-SAME: (ptr noundef [[PTR:%.*]]) #[[ATTR0]] {
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP2:%.*]] = load i128, ptr [[PTR]], align 16
+// CHECK-NEXT:[[TMP0:%.*]] = load i128, ptr [[PTR]], align 16
 // CHECK-NEXT:[[ADD_PTR:%.*]] = getelementptr inbounds i128, ptr [[PTR]], i64 1
-// CHECK-NEXT:store i128 [[TMP2]], ptr [[ADD_PTR]], align 16
+// CHECK-NEXT:store i128 [[TMP0]], ptr [[ADD_PTR]], align 16
 // CHECK-NEXT:ret void
 //
 void test_ld_st_p128(poly128_t * ptr) {
@@ -50,18 +50,18 @@
 }
 
 // CHECK-LABEL: define {{[^@]+}}@test_vmull_p64
-// CHECK-SAME: (i64 noundef [[A:%.*]], i64 noundef [[B:%.*]]) #[[ATTR0]] {
+// CHECK-SAME: (i64 noundef [[A:%.*]], i64 noundef [[B:%.*]]) #[[ATTR1:[0-9]+]] {
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[VMULL_P64_I:%.*]] = call <16 x i8> @llvm.aarch64.neon.pmull64(i64 [[A]], i64 [[B]])
 // CHECK-NEXT:[[VMULL_P641_I:%.*]] = bitcast <16 x i8> [[VMULL_P64_I]] to i128
 // CHECK-NEXT:ret i128 [[VMULL_P641_I]]
 //
-poly128_t test_vmull_p64(poly64_t a, poly64_t b) {
+__attribute__((target("aes"))) poly128_t test_vmull_p64(poly64_t a, poly64_t b) {
   return vmull_p64(a, b);
 }
 
 // CHECK-LABEL: define {{[^@]+}}@test_vmull_high_p64
-// CHECK-SAME: (<2 x i64> noundef [[A:%.*]], <2 x i64> noundef [[B:%.*]]) #[[ATTR1:[0-9]+]] {
+// CHECK-SAME: (<2 x i64> noundef [[A:%.*]], <2 x i64> noundef [[B:%.*]]) #[[ATTR2:[0-9]+]] {
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[SHUFFLE_I5:%.*]] = shufflevector <2 x i64> [[A]], <2 x i64> [[A]], <1 x i32> 
 // CHECK-NEXT:[[TMP0:%.*]] = bitcast <1 x i64> [[SHUFFLE_I5]] to i64
@@ -71,12 +71,12 @@
 // CHECK-NEXT:[[VMULL_P641_I_I:%.*]] = bitcast <16 x i8> [[VMULL_P64_I_I]] to i128
 // CHECK-NEXT:ret i128 [[VMULL_P641_I_I]]
 //
-poly128_t test_vmull_high_p64(poly64x2_t a, poly64x2_t b) {
+__attribute__((target("aes"))) poly128_t test_vmull_high_p64(poly64x2_t a, poly64x2_t b) {
   return vmull_high_p64(a, b);
 }
 
 // CHECK-LABEL: define {{[^@]+}}@test_vreinterpretq_p128_s8
-// CHECK-SAME: (<16 x i8> noundef [[A:%.*]]) #[[ATTR1]] {
+// CHECK-SAME: (<16 x i8> noundef [[A:%.*]]) #[[ATTR3:[0-9]+]] {
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[TMP0:%.*]] = bitcast <16 x i8> [[A]] to i128
 // CHECK-NEXT:ret i128 [[TMP0]]
@@ -86,7 +86,7 @@
 }
 
 // CHECK-LABEL: define {{[

[PATCH] D140432: [AArch64] Guard {vmull_p64, vmull_high_p64} with 'aes' target guard.

2022-12-21 Thread Mingming Liu via Phabricator via cfe-commits
mingmingl added a comment.

In D140432#4010143 , @dmgreen wrote:

> Thanks for putting together the patch. It may be worth mentioning in the 
> commit message that aes currently includes both FEAT_AES and FEAT_PMULL.
> Otherwise LGTM.

Thanks for reviews! Made the change in commit message and phab summary. Going 
to submit this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140432

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


[PATCH] D115232: [clangd] Indexing of standard library

2022-12-21 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang-tools-extra/clangd/ClangdServer.cpp:1008-1010
+  // TUScheduler is the only thing that starts background indexing work.
+  if (IndexTasks && !IndexTasks->wait(timeoutSeconds(TimeoutSeconds)))
+return false;

bnbarham wrote:
> @sammccall shouldn't we also be waiting for this to finish when 
> `ClangdServer` is destroyed? IIUC right now the both `FileIndex` itself 
> (stored in `ClangdServer`) and the actual `UpdateIndexCallbacks` (stored in 
> `TUScheduler`) can be freed while `indexStdlib` is running asynchronously, 
> resulting in a use-after-free on eg. `FIndex->updatePreamble(std::move(IF))`. 
> I was confused as to why this wasn't happening in the tests, but these lines 
> would explain it 😅 
> 
> Adding a `IndexTasks->wait()` to `~ClangdServer` fixes the crash I'm seeing 
> in the sourcekit-lsp tests (see 
> https://github.com/apple/llvm-project/pull/5837), though ideally we 
> (sourcekit-lsp) wouldn't be running any indexing at all. As far as I can tell 
> there's no way to turn off dynamic indexing now though, except for 
> `StandardLibrary` indexing through the config file (but not from clangd args)?
Thanks for flagging this!

We *almost* have the sequencing we need in ~ClangdServer:
 - when we fall off the end of ~ClangdServer it destroys all its members
 - `ClangdServer::IndexTasks` is declared after `FIndex`, so is destroyed first
 - ~AsyncTaskRunner calls `wait()`

But the task we schedule on `IndexTasks` captures a ref to 
`UpdateIndexCallbacks`, which is owned by the `TUScheduler`, which we 
explicitly destroy at the beginning of `~ClangdServer`.

However I think your patch is *also* not quite correct: we can wait for the 
tasks to be empty, but then the TUScheduler could fill it up again before we 
destroy TUScheduler.

Options include adding an explicit stop() to TUScheduler, changing TUScheduler 
to not (exclusively) own UpdateIndexCallbacks, or have the task not capture the 
callbacks by reference.
I'll try the latter first, which seems least invasive.

---

> ideally we (sourcekit-lsp) wouldn't be running any indexing at all. As far as 
> I can tell there's no way to turn off dynamic indexing now though, except for 
> StandardLibrary indexing through the config file (but not from clangd args)?

Clangd won't provide any top-level/namespace-level completions at all without 
dynamic index (index of preambles), and various other features won't work (docs 
on hover, include-fixer, type/call-hierarchy). We dropped support for disabling 
this at some point, as it didn't really seem usable and made features more 
complex if we tried to accommodate it. At a technical level it would be 
possible to disable I think, but I'd be really surprised if completion worked 
well, or if a language server without completion was useful.

> `StandardLibrary` indexing through the config file (but not from clangd args)

We've tried to move away from flags for options that are interesting to users, 
as config files are more flexible, more forgiving on errors, and allow 
different settings per-project in a consistent way. (We don't own the editors, 
so cross-editor consistency is important to being able to support users at 
all...)

I can see how requiring config to be materialized on disk could be inconvenient 
for IDEs though. I think we could add a general-purpose 
`--config-inline=` flag, and/or the ability to set config 
over LSP (this can be dynamic, accordingly bigger design space that might be 
hard to get right).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115232

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


[PATCH] D140486: [clangd] Fix crashing race in ClangdServer shutdown with stdlib indexing

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

In principle it's OK for stdlib-indexing tasks to run after the TUScheduler is
destroyed, as mostly they just update the dynamic index. We do drain the
stdlib-indexing queue before destroying the index.

However the task captures references to the PreambleCallbacks object, which is
owned by the TUScheduler. Once this is destroyed (explicitly, early in
~ClangdServer) an outstanding stdlib-indexing task may use-after-free.

The fix here is to avoid capturing references to the PreambleCallbacks.
Alternatives would be to have TUScheduler (exclusively) not own its callbacks
so they could live longer, or explicitly stopping the TUScheduler instead of
early-destroying it. These both seem more invasive.

See https://reviews.llvm.org/D115232 for some more context.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140486

Files:
  clang-tools-extra/clangd/ClangdServer.cpp


Index: clang-tools-extra/clangd/ClangdServer.cpp
===
--- clang-tools-extra/clangd/ClangdServer.cpp
+++ clang-tools-extra/clangd/ClangdServer.cpp
@@ -63,7 +63,7 @@
ClangdServer::Callbacks *ServerCallbacks,
const ThreadsafeFS &TFS, AsyncTaskRunner *Tasks)
   : FIndex(FIndex), ServerCallbacks(ServerCallbacks), TFS(TFS),
-Tasks(Tasks) {}
+Stdlib{std::make_shared()}, Tasks(Tasks) {}
 
   void onPreambleAST(PathRef Path, llvm::StringRef Version,
  const CompilerInvocation &CI, ASTContext &Ctx,
@@ -71,7 +71,7 @@
  const CanonicalIncludes &CanonIncludes) override {
 // If this preamble uses a standard library we haven't seen yet, index it.
 if (FIndex)
-  if (auto Loc = Stdlib.add(*CI.getLangOpts(), PP.getHeaderSearchInfo()))
+  if (auto Loc = Stdlib->add(*CI.getLangOpts(), PP.getHeaderSearchInfo()))
 indexStdlib(CI, std::move(*Loc));
 
 if (FIndex)
@@ -79,11 +79,22 @@
   }
 
   void indexStdlib(const CompilerInvocation &CI, StdLibLocation Loc) {
-auto Task = [this, LO(*CI.getLangOpts()), Loc(std::move(Loc)),
- CI(std::make_unique(CI))]() mutable {
+// This task is owned by Tasks, which outlives the TUScheduler and
+// therefore the UpdateIndexCallbacks.
+// We must be careful that the references we capture outlive TUScheduler.
+auto Task = [
+// Captured by value
+LO(*CI.getLangOpts()), Loc(std::move(Loc)),
+CI(std::make_unique(CI)),
+// External values that outlive ClangdServer
+TFS(&TFS),
+// Index outlives TUScheduler (declared first)
+FIndex(FIndex),
+// shared_ptr extends lifetime
+Stdlib(Stdlib)]() mutable {
   IndexFileIn IF;
-  IF.Symbols = indexStandardLibrary(std::move(CI), Loc, TFS);
-  if (Stdlib.isBest(LO))
+  IF.Symbols = indexStandardLibrary(std::move(CI), Loc, *TFS);
+  if (Stdlib->isBest(LO))
 FIndex->updatePreamble(std::move(IF));
 };
 if (Tasks)
@@ -128,7 +139,7 @@
   FileIndex *FIndex;
   ClangdServer::Callbacks *ServerCallbacks;
   const ThreadsafeFS &TFS;
-  StdLibSet Stdlib;
+  std::shared_ptr Stdlib;
   AsyncTaskRunner *Tasks;
 };
 


Index: clang-tools-extra/clangd/ClangdServer.cpp
===
--- clang-tools-extra/clangd/ClangdServer.cpp
+++ clang-tools-extra/clangd/ClangdServer.cpp
@@ -63,7 +63,7 @@
ClangdServer::Callbacks *ServerCallbacks,
const ThreadsafeFS &TFS, AsyncTaskRunner *Tasks)
   : FIndex(FIndex), ServerCallbacks(ServerCallbacks), TFS(TFS),
-Tasks(Tasks) {}
+Stdlib{std::make_shared()}, Tasks(Tasks) {}
 
   void onPreambleAST(PathRef Path, llvm::StringRef Version,
  const CompilerInvocation &CI, ASTContext &Ctx,
@@ -71,7 +71,7 @@
  const CanonicalIncludes &CanonIncludes) override {
 // If this preamble uses a standard library we haven't seen yet, index it.
 if (FIndex)
-  if (auto Loc = Stdlib.add(*CI.getLangOpts(), PP.getHeaderSearchInfo()))
+  if (auto Loc = Stdlib->add(*CI.getLangOpts(), PP.getHeaderSearchInfo()))
 indexStdlib(CI, std::move(*Loc));
 
 if (FIndex)
@@ -79,11 +79,22 @@
   }
 
   void indexStdlib(const CompilerInvocation &CI, StdLibLocation Loc) {
-auto Task = [this, LO(*CI.getLangOpts()), Loc(std::move(Loc)),
- CI(std::make_unique(CI))]() mutable {
+// This task is owned by Tasks, which outlives the TUScheduler and
+// therefore the UpdateI

[PATCH] D139701: [Clang] Emit "min-legal-vector-width" attribute for X86 only

2022-12-21 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added inline comments.



Comment at: llvm/docs/LangRef.rst:2235-2241
-``"min-legal-vector-width"=""``
-This attribute indicates the minimum legal vector width required by the
-calling convension. It is the maximum width of vector arguments and
-returnings in the function and functions called by this function. Because
-all the vectors are supposed to be legal type for compatibility.
-Backends are free to ignore the attribute if they don't need to support
-different maximum legal vector types or such information can be inferred by

This still should be documented somewhere. I don't know if we document any 
target attributes specifically in the langref


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139701

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


[PATCH] D139261: [Clang] Modify sanity check assert in AggExprEmitter::VisitInitListExpr to cover anonymous struct in a union GNU extension

2022-12-21 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik updated this revision to Diff 484613.
shafik added a comment.

- Add Release note


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

https://reviews.llvm.org/D139261

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/CodeGen/CGExprAgg.cpp
  clang/test/SemaCXX/anonymous-struct.cpp


Index: clang/test/SemaCXX/anonymous-struct.cpp
===
--- clang/test/SemaCXX/anonymous-struct.cpp
+++ clang/test/SemaCXX/anonymous-struct.cpp
@@ -189,3 +189,20 @@
   }
 } A; // expected-note {{given name 'A' for linkage purposes by this typedef}}
 }
+
+#if __cplusplus > 201103L
+namespace GH58800 {
+struct A {
+  union {
+struct {
+  float red = 0.0f;
+};
+  };
+};
+
+A GetA() {
+  A result{};
+  return result;
+}
+}
+#endif
Index: clang/lib/CodeGen/CGExprAgg.cpp
===
--- clang/lib/CodeGen/CGExprAgg.cpp
+++ clang/lib/CodeGen/CGExprAgg.cpp
@@ -1724,7 +1724,7 @@
   // Make sure that it's really an empty and not a failure of
   // semantic analysis.
   for (const auto *Field : record->fields())
-assert(Field->isUnnamedBitfield() && "Only unnamed bitfields allowed");
+assert((Field->isUnnamedBitfield() || 
Field->isAnonymousStructOrUnion()) && "Only unnamed bitfields or ananymous 
class allowed");
 #endif
   return;
 }
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -326,6 +326,9 @@
 - Fix bug where constant evaluation treated a pointer to member that points to
   a weak member as never being null. Such comparisons are now treated as
   non-constant.
+- Fix sanity check when value initializing an empty union so that it takes into
+  account anonymous structs which is a GNU extension. This fixes
+  `Issue 58800 `_
 
 Improvements to Clang's diagnostics
 ^^^


Index: clang/test/SemaCXX/anonymous-struct.cpp
===
--- clang/test/SemaCXX/anonymous-struct.cpp
+++ clang/test/SemaCXX/anonymous-struct.cpp
@@ -189,3 +189,20 @@
   }
 } A; // expected-note {{given name 'A' for linkage purposes by this typedef}}
 }
+
+#if __cplusplus > 201103L
+namespace GH58800 {
+struct A {
+  union {
+struct {
+  float red = 0.0f;
+};
+  };
+};
+
+A GetA() {
+  A result{};
+  return result;
+}
+}
+#endif
Index: clang/lib/CodeGen/CGExprAgg.cpp
===
--- clang/lib/CodeGen/CGExprAgg.cpp
+++ clang/lib/CodeGen/CGExprAgg.cpp
@@ -1724,7 +1724,7 @@
   // Make sure that it's really an empty and not a failure of
   // semantic analysis.
   for (const auto *Field : record->fields())
-assert(Field->isUnnamedBitfield() && "Only unnamed bitfields allowed");
+assert((Field->isUnnamedBitfield() || Field->isAnonymousStructOrUnion()) && "Only unnamed bitfields or ananymous class allowed");
 #endif
   return;
 }
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -326,6 +326,9 @@
 - Fix bug where constant evaluation treated a pointer to member that points to
   a weak member as never being null. Such comparisons are now treated as
   non-constant.
+- Fix sanity check when value initializing an empty union so that it takes into
+  account anonymous structs which is a GNU extension. This fixes
+  `Issue 58800 `_
 
 Improvements to Clang's diagnostics
 ^^^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D139261: [Clang] Modify sanity check assert in AggExprEmitter::VisitInitListExpr to cover anonymous struct in a union GNU extension

2022-12-21 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added inline comments.



Comment at: clang/lib/CodeGen/CGExprAgg.cpp:1688
   for (const auto *Field : record->fields())
-assert(Field->isUnnamedBitfield() && "Only unnamed bitfields allowed");
+assert((Field->isUnnamedBitfield() || 
Field->isAnonymousStructOrUnion()) && "Only unnamed bitfields or ananymous 
class allowed");
 #endif

aaron.ballman wrote:
> Guessing at the way to solve the 80-col limit issue, but do whatever 
> clang-format says.
This is what clang-format likes.


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

https://reviews.llvm.org/D139261

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


[PATCH] D115232: [clangd] Indexing of standard library

2022-12-21 Thread Ben Barham via Phabricator via cfe-commits
bnbarham added inline comments.



Comment at: clang-tools-extra/clangd/ClangdServer.cpp:1008-1010
+  // TUScheduler is the only thing that starts background indexing work.
+  if (IndexTasks && !IndexTasks->wait(timeoutSeconds(TimeoutSeconds)))
+return false;

sammccall wrote:
> bnbarham wrote:
> > @sammccall shouldn't we also be waiting for this to finish when 
> > `ClangdServer` is destroyed? IIUC right now the both `FileIndex` itself 
> > (stored in `ClangdServer`) and the actual `UpdateIndexCallbacks` (stored in 
> > `TUScheduler`) can be freed while `indexStdlib` is running asynchronously, 
> > resulting in a use-after-free on eg. 
> > `FIndex->updatePreamble(std::move(IF))`. I was confused as to why this 
> > wasn't happening in the tests, but these lines would explain it 😅 
> > 
> > Adding a `IndexTasks->wait()` to `~ClangdServer` fixes the crash I'm seeing 
> > in the sourcekit-lsp tests (see 
> > https://github.com/apple/llvm-project/pull/5837), though ideally we 
> > (sourcekit-lsp) wouldn't be running any indexing at all. As far as I can 
> > tell there's no way to turn off dynamic indexing now though, except for 
> > `StandardLibrary` indexing through the config file (but not from clangd 
> > args)?
> Thanks for flagging this!
> 
> We *almost* have the sequencing we need in ~ClangdServer:
>  - when we fall off the end of ~ClangdServer it destroys all its members
>  - `ClangdServer::IndexTasks` is declared after `FIndex`, so is destroyed 
> first
>  - ~AsyncTaskRunner calls `wait()`
> 
> But the task we schedule on `IndexTasks` captures a ref to 
> `UpdateIndexCallbacks`, which is owned by the `TUScheduler`, which we 
> explicitly destroy at the beginning of `~ClangdServer`.
> 
> However I think your patch is *also* not quite correct: we can wait for the 
> tasks to be empty, but then the TUScheduler could fill it up again before we 
> destroy TUScheduler.
> 
> Options include adding an explicit stop() to TUScheduler, changing 
> TUScheduler to not (exclusively) own UpdateIndexCallbacks, or have the task 
> not capture the callbacks by reference.
> I'll try the latter first, which seems least invasive.
> 
> ---
> 
> > ideally we (sourcekit-lsp) wouldn't be running any indexing at all. As far 
> > as I can tell there's no way to turn off dynamic indexing now though, 
> > except for StandardLibrary indexing through the config file (but not from 
> > clangd args)?
> 
> Clangd won't provide any top-level/namespace-level completions at all without 
> dynamic index (index of preambles), and various other features won't work 
> (docs on hover, include-fixer, type/call-hierarchy). We dropped support for 
> disabling this at some point, as it didn't really seem usable and made 
> features more complex if we tried to accommodate it. At a technical level it 
> would be possible to disable I think, but I'd be really surprised if 
> completion worked well, or if a language server without completion was useful.
> 
> > `StandardLibrary` indexing through the config file (but not from clangd 
> > args)
> 
> We've tried to move away from flags for options that are interesting to 
> users, as config files are more flexible, more forgiving on errors, and allow 
> different settings per-project in a consistent way. (We don't own the 
> editors, so cross-editor consistency is important to being able to support 
> users at all...)
> 
> I can see how requiring config to be materialized on disk could be 
> inconvenient for IDEs though. I think we could add a general-purpose 
> `--config-inline=` flag, and/or the ability to set 
> config over LSP (this can be dynamic, accordingly bigger design space that 
> might be hard to get right).
Ah, I didn't actually check `AsyncTaskRunner`. Makes sense it would wait though 
:). Thanks for looking into this in detail!

> or have the task not capture the callbacks by reference. I'll try the latter 
> first, which seems least invasive.

This + moving `FIndex` after `IndexTasks` seems reasonable to me.

> Clangd won't provide any top-level/namespace-level completions at all without 
> dynamic index (index of preambles), and various other features won't work 
> (docs on hover, include-fixer, type/call-hierarchy).

That's good to know - I assume this extends to indexing the stdlib as well, ie. 
the stdlib would be missing from top/namespace level completion if not indexed? 
Does the dynamic index grow with every opened file, or is it just the currently 
opened file? If disabling breaks everything it's not something we'd want to do, 
we just don't need it for find refs/etc.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115232

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


[clang] 475cc44 - [Clang] Modify sanity check assert in AggExprEmitter::VisitInitListExpr to cover anonymous struct in a union GNU extension

2022-12-21 Thread Shafik Yaghmour via cfe-commits

Author: Shafik Yaghmour
Date: 2022-12-21T10:50:05-08:00
New Revision: 475cc44a2cba45c5449a323c6b331ddc593bd8de

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

LOG: [Clang] Modify sanity check assert in AggExprEmitter::VisitInitListExpr to 
cover anonymous struct in a union GNU extension

AggExprEmitter::VisitInitListExpr sanity checks that an empty union is really
empty and not a semantic analysis failure. The assert is missing that we allow
anonymous structs as a GNU extension. I have updated the assert to take that 
into account.

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

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/CodeGen/CGExprAgg.cpp
clang/test/SemaCXX/anonymous-struct.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 09705a6b5b571..4ba28f5df5dc1 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -326,6 +326,9 @@ Bug Fixes
 - Fix bug where constant evaluation treated a pointer to member that points to
   a weak member as never being null. Such comparisons are now treated as
   non-constant.
+- Fix sanity check when value initializing an empty union so that it takes into
+  account anonymous structs which is a GNU extension. This fixes
+  `Issue 58800 `_
 
 Improvements to Clang's diagnostics
 ^^^

diff  --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp
index 8ba21f8fc0046..303bcc89f671c 100644
--- a/clang/lib/CodeGen/CGExprAgg.cpp
+++ b/clang/lib/CodeGen/CGExprAgg.cpp
@@ -1724,7 +1724,7 @@ void AggExprEmitter::VisitCXXParenListOrInitListExpr(
   // Make sure that it's really an empty and not a failure of
   // semantic analysis.
   for (const auto *Field : record->fields())
-assert(Field->isUnnamedBitfield() && "Only unnamed bitfields allowed");
+assert((Field->isUnnamedBitfield() || 
Field->isAnonymousStructOrUnion()) && "Only unnamed bitfields or ananymous 
class allowed");
 #endif
   return;
 }

diff  --git a/clang/test/SemaCXX/anonymous-struct.cpp 
b/clang/test/SemaCXX/anonymous-struct.cpp
index 7cf05ee3c49ae..e46bdc28d5059 100644
--- a/clang/test/SemaCXX/anonymous-struct.cpp
+++ b/clang/test/SemaCXX/anonymous-struct.cpp
@@ -189,3 +189,20 @@ typedef struct { // expected-warning {{anonymous 
non-C-compatible type}}
   }
 } A; // expected-note {{given name 'A' for linkage purposes by this typedef}}
 }
+
+#if __cplusplus > 201103L
+namespace GH58800 {
+struct A {
+  union {
+struct {
+  float red = 0.0f;
+};
+  };
+};
+
+A GetA() {
+  A result{};
+  return result;
+}
+}
+#endif



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


[PATCH] D139261: [Clang] Modify sanity check assert in AggExprEmitter::VisitInitListExpr to cover anonymous struct in a union GNU extension

2022-12-21 Thread Shafik Yaghmour 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 rG475cc44a2cba: [Clang] Modify sanity check assert in 
AggExprEmitter::VisitInitListExpr to… (authored by shafik).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139261

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/CodeGen/CGExprAgg.cpp
  clang/test/SemaCXX/anonymous-struct.cpp


Index: clang/test/SemaCXX/anonymous-struct.cpp
===
--- clang/test/SemaCXX/anonymous-struct.cpp
+++ clang/test/SemaCXX/anonymous-struct.cpp
@@ -189,3 +189,20 @@
   }
 } A; // expected-note {{given name 'A' for linkage purposes by this typedef}}
 }
+
+#if __cplusplus > 201103L
+namespace GH58800 {
+struct A {
+  union {
+struct {
+  float red = 0.0f;
+};
+  };
+};
+
+A GetA() {
+  A result{};
+  return result;
+}
+}
+#endif
Index: clang/lib/CodeGen/CGExprAgg.cpp
===
--- clang/lib/CodeGen/CGExprAgg.cpp
+++ clang/lib/CodeGen/CGExprAgg.cpp
@@ -1724,7 +1724,7 @@
   // Make sure that it's really an empty and not a failure of
   // semantic analysis.
   for (const auto *Field : record->fields())
-assert(Field->isUnnamedBitfield() && "Only unnamed bitfields allowed");
+assert((Field->isUnnamedBitfield() || 
Field->isAnonymousStructOrUnion()) && "Only unnamed bitfields or ananymous 
class allowed");
 #endif
   return;
 }
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -326,6 +326,9 @@
 - Fix bug where constant evaluation treated a pointer to member that points to
   a weak member as never being null. Such comparisons are now treated as
   non-constant.
+- Fix sanity check when value initializing an empty union so that it takes into
+  account anonymous structs which is a GNU extension. This fixes
+  `Issue 58800 `_
 
 Improvements to Clang's diagnostics
 ^^^


Index: clang/test/SemaCXX/anonymous-struct.cpp
===
--- clang/test/SemaCXX/anonymous-struct.cpp
+++ clang/test/SemaCXX/anonymous-struct.cpp
@@ -189,3 +189,20 @@
   }
 } A; // expected-note {{given name 'A' for linkage purposes by this typedef}}
 }
+
+#if __cplusplus > 201103L
+namespace GH58800 {
+struct A {
+  union {
+struct {
+  float red = 0.0f;
+};
+  };
+};
+
+A GetA() {
+  A result{};
+  return result;
+}
+}
+#endif
Index: clang/lib/CodeGen/CGExprAgg.cpp
===
--- clang/lib/CodeGen/CGExprAgg.cpp
+++ clang/lib/CodeGen/CGExprAgg.cpp
@@ -1724,7 +1724,7 @@
   // Make sure that it's really an empty and not a failure of
   // semantic analysis.
   for (const auto *Field : record->fields())
-assert(Field->isUnnamedBitfield() && "Only unnamed bitfields allowed");
+assert((Field->isUnnamedBitfield() || Field->isAnonymousStructOrUnion()) && "Only unnamed bitfields or ananymous class allowed");
 #endif
   return;
 }
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -326,6 +326,9 @@
 - Fix bug where constant evaluation treated a pointer to member that points to
   a weak member as never being null. Such comparisons are now treated as
   non-constant.
+- Fix sanity check when value initializing an empty union so that it takes into
+  account anonymous structs which is a GNU extension. This fixes
+  `Issue 58800 `_
 
 Improvements to Clang's diagnostics
 ^^^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D140433: [Clang] Add `nvptx-arch` tool to query installed NVIDIA GPUs

2022-12-21 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added inline comments.



Comment at: clang/tools/nvptx-arch/NVPTXArch.cpp:37
+return 1;
+  printf("CUDA error: %s\n", ErrStr);
+  return 1;

stderr?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140433

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


[PATCH] D115232: [clangd] Indexing of standard library

2022-12-21 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang-tools-extra/clangd/ClangdServer.cpp:1008-1010
+  // TUScheduler is the only thing that starts background indexing work.
+  if (IndexTasks && !IndexTasks->wait(timeoutSeconds(TimeoutSeconds)))
+return false;

bnbarham wrote:
> sammccall wrote:
> > bnbarham wrote:
> > > @sammccall shouldn't we also be waiting for this to finish when 
> > > `ClangdServer` is destroyed? IIUC right now the both `FileIndex` itself 
> > > (stored in `ClangdServer`) and the actual `UpdateIndexCallbacks` (stored 
> > > in `TUScheduler`) can be freed while `indexStdlib` is running 
> > > asynchronously, resulting in a use-after-free on eg. 
> > > `FIndex->updatePreamble(std::move(IF))`. I was confused as to why this 
> > > wasn't happening in the tests, but these lines would explain it 😅 
> > > 
> > > Adding a `IndexTasks->wait()` to `~ClangdServer` fixes the crash I'm 
> > > seeing in the sourcekit-lsp tests (see 
> > > https://github.com/apple/llvm-project/pull/5837), though ideally we 
> > > (sourcekit-lsp) wouldn't be running any indexing at all. As far as I can 
> > > tell there's no way to turn off dynamic indexing now though, except for 
> > > `StandardLibrary` indexing through the config file (but not from clangd 
> > > args)?
> > Thanks for flagging this!
> > 
> > We *almost* have the sequencing we need in ~ClangdServer:
> >  - when we fall off the end of ~ClangdServer it destroys all its members
> >  - `ClangdServer::IndexTasks` is declared after `FIndex`, so is destroyed 
> > first
> >  - ~AsyncTaskRunner calls `wait()`
> > 
> > But the task we schedule on `IndexTasks` captures a ref to 
> > `UpdateIndexCallbacks`, which is owned by the `TUScheduler`, which we 
> > explicitly destroy at the beginning of `~ClangdServer`.
> > 
> > However I think your patch is *also* not quite correct: we can wait for the 
> > tasks to be empty, but then the TUScheduler could fill it up again before 
> > we destroy TUScheduler.
> > 
> > Options include adding an explicit stop() to TUScheduler, changing 
> > TUScheduler to not (exclusively) own UpdateIndexCallbacks, or have the task 
> > not capture the callbacks by reference.
> > I'll try the latter first, which seems least invasive.
> > 
> > ---
> > 
> > > ideally we (sourcekit-lsp) wouldn't be running any indexing at all. As 
> > > far as I can tell there's no way to turn off dynamic indexing now though, 
> > > except for StandardLibrary indexing through the config file (but not from 
> > > clangd args)?
> > 
> > Clangd won't provide any top-level/namespace-level completions at all 
> > without dynamic index (index of preambles), and various other features 
> > won't work (docs on hover, include-fixer, type/call-hierarchy). We dropped 
> > support for disabling this at some point, as it didn't really seem usable 
> > and made features more complex if we tried to accommodate it. At a 
> > technical level it would be possible to disable I think, but I'd be really 
> > surprised if completion worked well, or if a language server without 
> > completion was useful.
> > 
> > > `StandardLibrary` indexing through the config file (but not from clangd 
> > > args)
> > 
> > We've tried to move away from flags for options that are interesting to 
> > users, as config files are more flexible, more forgiving on errors, and 
> > allow different settings per-project in a consistent way. (We don't own the 
> > editors, so cross-editor consistency is important to being able to support 
> > users at all...)
> > 
> > I can see how requiring config to be materialized on disk could be 
> > inconvenient for IDEs though. I think we could add a general-purpose 
> > `--config-inline=` flag, and/or the ability to set 
> > config over LSP (this can be dynamic, accordingly bigger design space that 
> > might be hard to get right).
> Ah, I didn't actually check `AsyncTaskRunner`. Makes sense it would wait 
> though :). Thanks for looking into this in detail!
> 
> > or have the task not capture the callbacks by reference. I'll try the 
> > latter first, which seems least invasive.
> 
> This + moving `FIndex` after `IndexTasks` seems reasonable to me.
> 
> > Clangd won't provide any top-level/namespace-level completions at all 
> > without dynamic index (index of preambles), and various other features 
> > won't work (docs on hover, include-fixer, type/call-hierarchy).
> 
> That's good to know - I assume this extends to indexing the stdlib as well, 
> ie. the stdlib would be missing from top/namespace level completion if not 
> indexed? Does the dynamic index grow with every opened file, or is it just 
> the currently opened file? If disabling breaks everything it's not something 
> we'd want to do, we just don't need it for find refs/etc.
> This + moving FIndex after IndexTasks seems reasonable to me.

I sent D140486. FIndex should be **before** IndexTasks in order to outlive it, 
unless I'm missing something.

> I assume this ex

[clang] c847e22 - [AArch64] Guard {vmull_p64, vmull_high_p64} with 'aes' target guard.

2022-12-21 Thread Mingming Liu via cfe-commits

Author: Mingming Liu
Date: 2022-12-21T11:02:27-08:00
New Revision: c847e22db33e4625b1ad58b631f57d7d1e1944ca

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

LOG: [AArch64] Guard {vmull_p64, vmull_high_p64} with 'aes' target guard.

The 'aes' target guard includes both FEAT_AES and FEAT_PMULL currently.

In this way, cpp code that uses these intrinsics without specifying the 
required extension gets better hint.
- Before, compile crashes with LLVM ISel internal message (see issue [[ 
https://github.com/llvm/llvm-project/issues/59599 | 59599 ]]).
- After, clang hints that target 'aes' is required in the command.

Reviewed By: dmgreen

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

Added: 


Modified: 
clang/include/clang/Basic/arm_neon.td
clang/test/CodeGen/aarch64-poly128.c
clang/test/Sema/aarch64-neon-target.c

Removed: 




diff  --git a/clang/include/clang/Basic/arm_neon.td 
b/clang/include/clang/Basic/arm_neon.td
index 4288e9eb69d07..94dfe80acc358 100644
--- a/clang/include/clang/Basic/arm_neon.td
+++ b/clang/include/clang/Basic/arm_neon.td
@@ -957,8 +957,10 @@ def VQDMLAL_HIGH : SOpInst<"vqdmlal_high", "(>Q)(>Q)QQ", 
"si", OP_QDMLALHi>;
 def VQDMLAL_HIGH_N : SOpInst<"vqdmlal_high_n", "(>Q)(>Q)Q1", "si", 
OP_QDMLALHi_N>;
 def VQDMLSL_HIGH : SOpInst<"vqdmlsl_high", "(>Q)(>Q)QQ", "si", OP_QDMLSLHi>;
 def VQDMLSL_HIGH_N : SOpInst<"vqdmlsl_high_n", "(>Q)(>Q)Q1", "si", 
OP_QDMLSLHi_N>;
-def VMULL_P64: SInst<"vmull", "(1>)11", "Pl">;
-def VMULL_HIGH_P64 : SOpInst<"vmull_high", "(1>)..", "HPl", OP_MULLHi_P64>;
+let TargetGuard = "aes" in {
+  def VMULL_P64: SInst<"vmull", "(1>)11", "Pl">;
+  def VMULL_HIGH_P64 : SOpInst<"vmull_high", "(1>)..", "HPl", OP_MULLHi_P64>;
+}
 
 
 


diff  --git a/clang/test/CodeGen/aarch64-poly128.c 
b/clang/test/CodeGen/aarch64-poly128.c
index d73390c7f6aa1..f188632468fc8 100644
--- a/clang/test/CodeGen/aarch64-poly128.c
+++ b/clang/test/CodeGen/aarch64-poly128.c
@@ -28,8 +28,8 @@ void test_vstrq_p128(poly128_t * ptr, poly128_t val) {
 // CHECK-LABEL: define {{[^@]+}}@test_vldrq_p128
 // CHECK-SAME: (ptr noundef [[PTR:%.*]]) #[[ATTR0]] {
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP2:%.*]] = load i128, ptr [[PTR]], align 16
-// CHECK-NEXT:ret i128 [[TMP2]]
+// CHECK-NEXT:[[TMP0:%.*]] = load i128, ptr [[PTR]], align 16
+// CHECK-NEXT:ret i128 [[TMP0]]
 //
 poly128_t test_vldrq_p128(poly128_t * ptr) {
   return vldrq_p128(ptr);
@@ -39,9 +39,9 @@ poly128_t test_vldrq_p128(poly128_t * ptr) {
 // CHECK-LABEL: define {{[^@]+}}@test_ld_st_p128
 // CHECK-SAME: (ptr noundef [[PTR:%.*]]) #[[ATTR0]] {
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP2:%.*]] = load i128, ptr [[PTR]], align 16
+// CHECK-NEXT:[[TMP0:%.*]] = load i128, ptr [[PTR]], align 16
 // CHECK-NEXT:[[ADD_PTR:%.*]] = getelementptr inbounds i128, ptr [[PTR]], 
i64 1
-// CHECK-NEXT:store i128 [[TMP2]], ptr [[ADD_PTR]], align 16
+// CHECK-NEXT:store i128 [[TMP0]], ptr [[ADD_PTR]], align 16
 // CHECK-NEXT:ret void
 //
 void test_ld_st_p128(poly128_t * ptr) {
@@ -50,18 +50,18 @@ void test_ld_st_p128(poly128_t * ptr) {
 }
 
 // CHECK-LABEL: define {{[^@]+}}@test_vmull_p64
-// CHECK-SAME: (i64 noundef [[A:%.*]], i64 noundef [[B:%.*]]) #[[ATTR0]] {
+// CHECK-SAME: (i64 noundef [[A:%.*]], i64 noundef [[B:%.*]]) 
#[[ATTR1:[0-9]+]] {
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[VMULL_P64_I:%.*]] = call <16 x i8> 
@llvm.aarch64.neon.pmull64(i64 [[A]], i64 [[B]])
 // CHECK-NEXT:[[VMULL_P641_I:%.*]] = bitcast <16 x i8> [[VMULL_P64_I]] to 
i128
 // CHECK-NEXT:ret i128 [[VMULL_P641_I]]
 //
-poly128_t test_vmull_p64(poly64_t a, poly64_t b) {
+__attribute__((target("aes"))) poly128_t test_vmull_p64(poly64_t a, poly64_t 
b) {
   return vmull_p64(a, b);
 }
 
 // CHECK-LABEL: define {{[^@]+}}@test_vmull_high_p64
-// CHECK-SAME: (<2 x i64> noundef [[A:%.*]], <2 x i64> noundef [[B:%.*]]) 
#[[ATTR1:[0-9]+]] {
+// CHECK-SAME: (<2 x i64> noundef [[A:%.*]], <2 x i64> noundef [[B:%.*]]) 
#[[ATTR2:[0-9]+]] {
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[SHUFFLE_I5:%.*]] = shufflevector <2 x i64> [[A]], <2 x 
i64> [[A]], <1 x i32> 
 // CHECK-NEXT:[[TMP0:%.*]] = bitcast <1 x i64> [[SHUFFLE_I5]] to i64
@@ -71,12 +71,12 @@ poly128_t test_vmull_p64(poly64_t a, poly64_t b) {
 // CHECK-NEXT:[[VMULL_P641_I_I:%.*]] = bitcast <16 x i8> [[VMULL_P64_I_I]] 
to i128
 // CHECK-NEXT:ret i128 [[VMULL_P641_I_I]]
 //
-poly128_t test_vmull_high_p64(poly64x2_t a, poly64x2_t b) {
+__attribute__((target("aes"))) poly128_t test_vmull_high_p64(poly64x2_t a, 
poly64x2_t b) {
   return vmull_high_p64(a, b);
 }
 
 // CHECK-LABEL: define {{[^@]+}}@test_vreinterpretq_p128_s8
-// CHECK-SAME: (<16 

[PATCH] D140432: [AArch64] Guard {vmull_p64, vmull_high_p64} with 'aes' target guard.

2022-12-21 Thread Mingming Liu 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 rGc847e22db33e: [AArch64] Guard {vmull_p64, vmull_high_p64} 
with 'aes' target guard. (authored by mingmingl).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140432

Files:
  clang/include/clang/Basic/arm_neon.td
  clang/test/CodeGen/aarch64-poly128.c
  clang/test/Sema/aarch64-neon-target.c

Index: clang/test/Sema/aarch64-neon-target.c
===
--- clang/test/Sema/aarch64-neon-target.c
+++ clang/test/Sema/aarch64-neon-target.c
@@ -60,7 +60,7 @@
   vrnd32xq_f32(v4f32);
 }
 
-void undefined(uint32x2_t v2i32, uint32x4_t v4i32, uint16x8_t v8i16, uint8x16_t v16i8, uint8x8_t v8i8, float32x2_t v2f32, float32x4_t v4f32, float16x4_t v4f16, float64x2_t v2f64, bfloat16x4_t v4bf16, __bf16 bf16) {
+void undefined(uint32x2_t v2i32, uint32x4_t v4i32, uint16x8_t v8i16, uint8x16_t v16i8, uint8x8_t v8i8, float32x2_t v2f32, float32x4_t v4f32, float16x4_t v4f16, float64x2_t v2f64, bfloat16x4_t v4bf16, __bf16 bf16, poly64_t poly64, poly64x2_t poly64x2) {
   // dotprod
   vdot_u32(v2i32, v8i8, v8i8); // expected-error {{always_inline function 'vdot_u32' requires target feature 'dotprod'}}
   vdot_laneq_u32(v2i32, v8i8, v16i8, 1); // expected-error {{always_inline function 'vdot_u32' requires target feature 'dotprod'}}
@@ -92,4 +92,8 @@
   vcmlaq_rot270_laneq_f64(v2f64, v2f64, v2f64, 1); // expected-error {{always_inline function 'vcmlaq_rot270_f64' requires target feature 'v8.3a'}}
   // 8.5 - frint
   vrnd32xq_f32(v4f32); // expected-error {{always_inline function 'vrnd32xq_f32' requires target feature 'v8.5a'}}
+
+  vmull_p64(poly64, poly64);  // expected-error {{always_inline function 'vmull_p64' requires target feature 'aes'}}
+  vmull_high_p64(poly64x2, poly64x2);  // expected-error {{always_inline function 'vmull_high_p64' requires target feature 'aes'}}
+
 }
Index: clang/test/CodeGen/aarch64-poly128.c
===
--- clang/test/CodeGen/aarch64-poly128.c
+++ clang/test/CodeGen/aarch64-poly128.c
@@ -28,8 +28,8 @@
 // CHECK-LABEL: define {{[^@]+}}@test_vldrq_p128
 // CHECK-SAME: (ptr noundef [[PTR:%.*]]) #[[ATTR0]] {
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP2:%.*]] = load i128, ptr [[PTR]], align 16
-// CHECK-NEXT:ret i128 [[TMP2]]
+// CHECK-NEXT:[[TMP0:%.*]] = load i128, ptr [[PTR]], align 16
+// CHECK-NEXT:ret i128 [[TMP0]]
 //
 poly128_t test_vldrq_p128(poly128_t * ptr) {
   return vldrq_p128(ptr);
@@ -39,9 +39,9 @@
 // CHECK-LABEL: define {{[^@]+}}@test_ld_st_p128
 // CHECK-SAME: (ptr noundef [[PTR:%.*]]) #[[ATTR0]] {
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP2:%.*]] = load i128, ptr [[PTR]], align 16
+// CHECK-NEXT:[[TMP0:%.*]] = load i128, ptr [[PTR]], align 16
 // CHECK-NEXT:[[ADD_PTR:%.*]] = getelementptr inbounds i128, ptr [[PTR]], i64 1
-// CHECK-NEXT:store i128 [[TMP2]], ptr [[ADD_PTR]], align 16
+// CHECK-NEXT:store i128 [[TMP0]], ptr [[ADD_PTR]], align 16
 // CHECK-NEXT:ret void
 //
 void test_ld_st_p128(poly128_t * ptr) {
@@ -50,18 +50,18 @@
 }
 
 // CHECK-LABEL: define {{[^@]+}}@test_vmull_p64
-// CHECK-SAME: (i64 noundef [[A:%.*]], i64 noundef [[B:%.*]]) #[[ATTR0]] {
+// CHECK-SAME: (i64 noundef [[A:%.*]], i64 noundef [[B:%.*]]) #[[ATTR1:[0-9]+]] {
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[VMULL_P64_I:%.*]] = call <16 x i8> @llvm.aarch64.neon.pmull64(i64 [[A]], i64 [[B]])
 // CHECK-NEXT:[[VMULL_P641_I:%.*]] = bitcast <16 x i8> [[VMULL_P64_I]] to i128
 // CHECK-NEXT:ret i128 [[VMULL_P641_I]]
 //
-poly128_t test_vmull_p64(poly64_t a, poly64_t b) {
+__attribute__((target("aes"))) poly128_t test_vmull_p64(poly64_t a, poly64_t b) {
   return vmull_p64(a, b);
 }
 
 // CHECK-LABEL: define {{[^@]+}}@test_vmull_high_p64
-// CHECK-SAME: (<2 x i64> noundef [[A:%.*]], <2 x i64> noundef [[B:%.*]]) #[[ATTR1:[0-9]+]] {
+// CHECK-SAME: (<2 x i64> noundef [[A:%.*]], <2 x i64> noundef [[B:%.*]]) #[[ATTR2:[0-9]+]] {
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[SHUFFLE_I5:%.*]] = shufflevector <2 x i64> [[A]], <2 x i64> [[A]], <1 x i32> 
 // CHECK-NEXT:[[TMP0:%.*]] = bitcast <1 x i64> [[SHUFFLE_I5]] to i64
@@ -71,12 +71,12 @@
 // CHECK-NEXT:[[VMULL_P641_I_I:%.*]] = bitcast <16 x i8> [[VMULL_P64_I_I]] to i128
 // CHECK-NEXT:ret i128 [[VMULL_P641_I_I]]
 //
-poly128_t test_vmull_high_p64(poly64x2_t a, poly64x2_t b) {
+__attribute__((target("aes"))) poly128_t test_vmull_high_p64(poly64x2_t a, poly64x2_t b) {
   return vmull_high_p64(a, b);
 }
 
 // CHECK-LABEL: define {{[^@]+}}@test_vreinterpretq_p128_s8
-// CHECK-SAME: (<16 x i8> noundef [[A:%.*]]) #[[ATTR1]] {
+// CHECK-SAME: (<16 x i8> noundef [[A:%.*]]) #[[ATTR3:[0-9]+]] {
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[TMP0:%.*]] = bitcast <16 x i8> [[A]] to i128
 // CHEC

[PATCH] D115232: [clangd] Indexing of standard library

2022-12-21 Thread Ben Barham via Phabricator via cfe-commits
bnbarham added inline comments.



Comment at: clang-tools-extra/clangd/ClangdServer.cpp:1008-1010
+  // TUScheduler is the only thing that starts background indexing work.
+  if (IndexTasks && !IndexTasks->wait(timeoutSeconds(TimeoutSeconds)))
+return false;

sammccall wrote:
> bnbarham wrote:
> > sammccall wrote:
> > > bnbarham wrote:
> > > > @sammccall shouldn't we also be waiting for this to finish when 
> > > > `ClangdServer` is destroyed? IIUC right now the both `FileIndex` itself 
> > > > (stored in `ClangdServer`) and the actual `UpdateIndexCallbacks` 
> > > > (stored in `TUScheduler`) can be freed while `indexStdlib` is running 
> > > > asynchronously, resulting in a use-after-free on eg. 
> > > > `FIndex->updatePreamble(std::move(IF))`. I was confused as to why this 
> > > > wasn't happening in the tests, but these lines would explain it 😅 
> > > > 
> > > > Adding a `IndexTasks->wait()` to `~ClangdServer` fixes the crash I'm 
> > > > seeing in the sourcekit-lsp tests (see 
> > > > https://github.com/apple/llvm-project/pull/5837), though ideally we 
> > > > (sourcekit-lsp) wouldn't be running any indexing at all. As far as I 
> > > > can tell there's no way to turn off dynamic indexing now though, except 
> > > > for `StandardLibrary` indexing through the config file (but not from 
> > > > clangd args)?
> > > Thanks for flagging this!
> > > 
> > > We *almost* have the sequencing we need in ~ClangdServer:
> > >  - when we fall off the end of ~ClangdServer it destroys all its members
> > >  - `ClangdServer::IndexTasks` is declared after `FIndex`, so is destroyed 
> > > first
> > >  - ~AsyncTaskRunner calls `wait()`
> > > 
> > > But the task we schedule on `IndexTasks` captures a ref to 
> > > `UpdateIndexCallbacks`, which is owned by the `TUScheduler`, which we 
> > > explicitly destroy at the beginning of `~ClangdServer`.
> > > 
> > > However I think your patch is *also* not quite correct: we can wait for 
> > > the tasks to be empty, but then the TUScheduler could fill it up again 
> > > before we destroy TUScheduler.
> > > 
> > > Options include adding an explicit stop() to TUScheduler, changing 
> > > TUScheduler to not (exclusively) own UpdateIndexCallbacks, or have the 
> > > task not capture the callbacks by reference.
> > > I'll try the latter first, which seems least invasive.
> > > 
> > > ---
> > > 
> > > > ideally we (sourcekit-lsp) wouldn't be running any indexing at all. As 
> > > > far as I can tell there's no way to turn off dynamic indexing now 
> > > > though, except for StandardLibrary indexing through the config file 
> > > > (but not from clangd args)?
> > > 
> > > Clangd won't provide any top-level/namespace-level completions at all 
> > > without dynamic index (index of preambles), and various other features 
> > > won't work (docs on hover, include-fixer, type/call-hierarchy). We 
> > > dropped support for disabling this at some point, as it didn't really 
> > > seem usable and made features more complex if we tried to accommodate it. 
> > > At a technical level it would be possible to disable I think, but I'd be 
> > > really surprised if completion worked well, or if a language server 
> > > without completion was useful.
> > > 
> > > > `StandardLibrary` indexing through the config file (but not from clangd 
> > > > args)
> > > 
> > > We've tried to move away from flags for options that are interesting to 
> > > users, as config files are more flexible, more forgiving on errors, and 
> > > allow different settings per-project in a consistent way. (We don't own 
> > > the editors, so cross-editor consistency is important to being able to 
> > > support users at all...)
> > > 
> > > I can see how requiring config to be materialized on disk could be 
> > > inconvenient for IDEs though. I think we could add a general-purpose 
> > > `--config-inline=` flag, and/or the ability to set 
> > > config over LSP (this can be dynamic, accordingly bigger design space 
> > > that might be hard to get right).
> > Ah, I didn't actually check `AsyncTaskRunner`. Makes sense it would wait 
> > though :). Thanks for looking into this in detail!
> > 
> > > or have the task not capture the callbacks by reference. I'll try the 
> > > latter first, which seems least invasive.
> > 
> > This + moving `FIndex` after `IndexTasks` seems reasonable to me.
> > 
> > > Clangd won't provide any top-level/namespace-level completions at all 
> > > without dynamic index (index of preambles), and various other features 
> > > won't work (docs on hover, include-fixer, type/call-hierarchy).
> > 
> > That's good to know - I assume this extends to indexing the stdlib as well, 
> > ie. the stdlib would be missing from top/namespace level completion if not 
> > indexed? Does the dynamic index grow with every opened file, or is it just 
> > the currently opened file? If disabling breaks everything it's not 
> > something we'd want to do, we just don't need it for find refs/etc.
> > Th

[clang] 6c3a290 - Headers: further refine the `stdatomic.h` MSVC inclusion

2022-12-21 Thread Saleem Abdulrasool via cfe-commits

Author: Saleem Abdulrasool
Date: 2022-12-21T19:09:10Z
New Revision: 6c3a2902f1f8d102aa5b3cd37def4f1420ac0c80

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

LOG: Headers: further refine the `stdatomic.h` MSVC inclusion

The `stdatomic.h` header cannot be included under MSVC when in C++ mode
as the toolsets prior to 17.5.0 Preview 2 do not support the C11
atomics.  However, some toolsets prior to the aforementioned version
support the atomics under the C++ mode.  In these versions the MSVC
toolset protects against the contamination by entirely eliding the
declarations, resulting in build failures in some cases.  Unfortunately,
e0c3142af075e2ef89395dbed5939071345eb622 accidentally regressed the C
case when fixing the C++ support.

Unfortunately, we cannot test this reliably as we need to inject a
header after the resource path as a system header path, which we do not
have a reliable means of doing.

Fixes: #59640

Added: 


Modified: 
clang/lib/Headers/stdatomic.h

Removed: 




diff  --git a/clang/lib/Headers/stdatomic.h b/clang/lib/Headers/stdatomic.h
index 9093851b76cfc..0f893beea6ca2 100644
--- a/clang/lib/Headers/stdatomic.h
+++ b/clang/lib/Headers/stdatomic.h
@@ -20,7 +20,7 @@
  */
 #if __STDC_HOSTED__ && 
\
 __has_include_next() &&   
\
-!(defined(_MSC_VER) && defined(__cplusplus) && __cplusplus < 202002L)
+(!defined(_MSC_VER) || (defined(__cplusplus) && __cplusplus >= 202002L))
 # include_next 
 #else
 



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


[PATCH] D140489: Add builtin_elementwise_log

2022-12-21 Thread Joshua Batista via Phabricator via cfe-commits
bob80905 created this revision.
bob80905 added reviewers: python3kgae, beanz.
Herald added a subscriber: Anastasia.
Herald added a project: All.
bob80905 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Add codegen for llvm log elementwise builtin
The log elementwise builtin is necessary for HLSL codegen.
Tests were added to make sure that the expected errors are encountered when 
these functions are given inputs of incompatible types.
The new builtin is restricted to floating point types only.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140489

Files:
  clang/docs/LanguageExtensions.rst
  clang/docs/ReleaseNotes.rst


Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -845,6 +845,7 @@
   unsafe floating-point optimizations use ``-funsafe-math-optimizations`` or
   ``-ffast-math`` instead.
 - Add ``__builtin_elementwise_sin`` and ``__builtin_elementwise_cos`` builtins 
for floating point types only.
+- Add ``__builtin_elementwise_log``builtin for floating point types only.
 
 Internal API Changes
 
Index: clang/docs/LanguageExtensions.rst
===
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -635,6 +635,7 @@
  T __builtin_elementwise_sin(T x)return the sine of x interpreted 
as an angle in radians  floating point types
  T __builtin_elementwise_cos(T x)return the cosine of x 
interpreted as an angle in radiansfloating point types
  T __builtin_elementwise_floor(T x)  return the largest integral value 
less than or equal to xfloating point types
+ T __builtin_elementwise_log(T x)return the natural logarithm of x 
   floating point types
  T __builtin_elementwise_roundeven(T x)  round x to the nearest integer 
value in floating point format,   floating point types
  rounding halfway cases to even 
(that is, to the nearest value
  that is an even integer), 
regardless of the current rounding


Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -845,6 +845,7 @@
   unsafe floating-point optimizations use ``-funsafe-math-optimizations`` or
   ``-ffast-math`` instead.
 - Add ``__builtin_elementwise_sin`` and ``__builtin_elementwise_cos`` builtins for floating point types only.
+- Add ``__builtin_elementwise_log``builtin for floating point types only.
 
 Internal API Changes
 
Index: clang/docs/LanguageExtensions.rst
===
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -635,6 +635,7 @@
  T __builtin_elementwise_sin(T x)return the sine of x interpreted as an angle in radians  floating point types
  T __builtin_elementwise_cos(T x)return the cosine of x interpreted as an angle in radiansfloating point types
  T __builtin_elementwise_floor(T x)  return the largest integral value less than or equal to xfloating point types
+ T __builtin_elementwise_log(T x)return the natural logarithm of xfloating point types
  T __builtin_elementwise_roundeven(T x)  round x to the nearest integer value in floating point format,   floating point types
  rounding halfway cases to even (that is, to the nearest value
  that is an even integer), regardless of the current rounding
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D140489: Add builtin_elementwise_log

2022-12-21 Thread Joshua Batista via Phabricator via cfe-commits
bob80905 updated this revision to Diff 484633.
bob80905 added a comment.
Herald added subscribers: pcwang-thead, frasercrmck, luismarques, apazos, 
sameer.abuasal, s.egerton, Jim, jocewei, PkmX, the_o, brucehoult, 
MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, niosHD, sabuasal, 
simoncook, johnrusso, rbar, asb.

add both commits


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140489

Files:
  clang/docs/LanguageExtensions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/Builtins.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/builtins-elementwise-math.c
  clang/test/Sema/aarch64-sve-vector-log-ops.c
  clang/test/Sema/builtins-elementwise-math.c
  clang/test/Sema/riscv-sve-vector-log-ops.c
  clang/test/SemaCXX/builtins-elementwise-math.cpp

Index: clang/test/SemaCXX/builtins-elementwise-math.cpp
===
--- clang/test/SemaCXX/builtins-elementwise-math.cpp
+++ clang/test/SemaCXX/builtins-elementwise-math.cpp
@@ -73,3 +73,10 @@
   static_assert(!is_const::value);
   static_assert(!is_const::value);
 }
+
+void test_builtin_elementwise_log() {
+  const float a = 42.0;
+  float b = 42.3;
+  static_assert(!is_const::value);
+  static_assert(!is_const::value);
+}
Index: clang/test/Sema/riscv-sve-vector-log-ops.c
===
--- /dev/null
+++ clang/test/Sema/riscv-sve-vector-log-ops.c
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -triple riscv64 -target-feature +f -target-feature +d \
+// RUN:   -target-feature +v -target-feature +zfh -target-feature +experimental-zvfh \
+// RUN:   -disable-O0-optnone -o - -fsyntax-only %s -verify 
+// REQUIRES: riscv-registered-target
+
+#include 
+
+
+vfloat32mf2_t test_sin_vv_i8mf8(vfloat32mf2_t v) {
+
+  return __builtin_elementwise_sin(v);
+  // expected-error@-1 {{1st argument must be a vector, integer or floating point type}}
+}
Index: clang/test/Sema/builtins-elementwise-math.c
===
--- clang/test/Sema/builtins-elementwise-math.c
+++ clang/test/Sema/builtins-elementwise-math.c
@@ -322,6 +322,27 @@
   // expected-error@-1 {{1st argument must be a floating point type (was 'unsigned4' (vector of 4 'unsigned int' values))}}
 }
 
+void test_builtin_elementwise_log(int i, float f, double d, float4 v, int3 iv, unsigned u, unsigned4 uv) {
+
+  struct Foo s = __builtin_elementwise_log(f);
+  // expected-error@-1 {{initializing 'struct Foo' with an expression of incompatible type 'float'}}
+
+  i = __builtin_elementwise_log();
+  // expected-error@-1 {{too few arguments to function call, expected 1, have 0}}
+
+  i = __builtin_elementwise_log(i);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'int')}}
+
+  i = __builtin_elementwise_log(f, f);
+  // expected-error@-1 {{too many arguments to function call, expected 1, have 2}}
+
+  u = __builtin_elementwise_log(u);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'unsigned int')}}
+
+  uv = __builtin_elementwise_log(uv);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'unsigned4' (vector of 4 'unsigned int' values))}}
+}
+
 void test_builtin_elementwise_roundeven(int i, float f, double d, float4 v, int3 iv, unsigned u, unsigned4 uv) {
 
   struct Foo s = __builtin_elementwise_roundeven(f);
Index: clang/test/Sema/aarch64-sve-vector-log-ops.c
===
--- /dev/null
+++ clang/test/Sema/aarch64-sve-vector-log-ops.c
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -triple aarch64 -target-feature +f -target-feature +d \
+// RUN:   -target-feature +v -target-feature +zfh  -target-feature +sve -target-feature +experimental-zvfh \
+// RUN:   -disable-O0-optnone -o - -fsyntax-only %s -verify 
+// REQUIRES: aarch64-registered-target
+
+#include 
+
+svfloat32_t test_log_vv_i8mf8(svfloat32_t v) {
+
+  return __builtin_elementwise_log(v);
+  // expected-error@-1 {{1st argument must be a vector, integer or floating point type}}
+}
Index: clang/test/CodeGen/builtins-elementwise-math.c
===
--- clang/test/CodeGen/builtins-elementwise-math.c
+++ clang/test/CodeGen/builtins-elementwise-math.c
@@ -365,6 +365,22 @@
   vf2 = __builtin_elementwise_floor(vf1);
 }
 
+void test_builtin_elementwise_log(float f1, float f2, double d1, double d2,
+  float4 vf1, float4 vf2) {
+  // CHECK-LABEL: define void @test_builtin_elementwise_log(
+  // CHECK:  [[F1:%.+]] = load float, ptr %f1.addr, align 4
+  // CHECK-NEXT:  call float @llvm.log.f32(float [[F1]])
+  f2 = __builtin_elementwise_log(f1);
+
+  // CHECK:  [[D1:%.+]] = load double, ptr %d1.addr, align 8
+  // CHECK-NEXT: call double @llvm.log.f64(double [[D1]])
+  d2 = __bui

[PATCH] D140433: [Clang] Add `nvptx-arch` tool to query installed NVIDIA GPUs

2022-12-21 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 updated this revision to Diff 484637.
jhuber6 added a comment.

Print to `stderr` and only return `1` if thre was an actual error. A lack of 
devices is considered a success and we print nothing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140433

Files:
  clang/tools/CMakeLists.txt
  clang/tools/nvptx-arch/CMakeLists.txt
  clang/tools/nvptx-arch/NVPTXArch.cpp

Index: clang/tools/nvptx-arch/NVPTXArch.cpp
===
--- /dev/null
+++ clang/tools/nvptx-arch/NVPTXArch.cpp
@@ -0,0 +1,72 @@
+//===- NVPTXArch.cpp - list installed NVPTX devies --*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file implements a tool for detecting name of CUDA gpus installed in the
+// system.
+//
+//===--===//
+
+#if defined(__has_include)
+#if __has_include("cuda.h")
+#include "cuda.h"
+#define CUDA_HEADER_FOUND 1
+#else
+#define CUDA_HEADER_FOUND 0
+#endif
+#else
+#define CUDA_HEADER_FOUND 0
+#endif
+
+#if !CUDA_HEADER_FOUND
+int main() { return 1; }
+#else
+
+#include 
+#include 
+
+static int handleError(CUresult Err) {
+  const char *ErrStr = nullptr;
+  CUresult Result = cuGetErrorString(Err, &ErrStr);
+  if (Result != CUDA_SUCCESS)
+return EXIT_FAILURE;
+  fprintf(stderr, "CUDA error: %s\n", ErrStr);
+  return EXIT_FAILURE;
+}
+
+int main() {
+  if (CUresult Err = cuInit(0)) {
+if (Err == CUDA_ERROR_NO_DEVICE)
+  return EXIT_SUCCESS;
+else
+  return handleError(Err);
+  }
+
+  int Count = 0;
+  if (CUresult Err = cuDeviceGetCount(&Count))
+return handleError(Err);
+  if (Count == 0)
+return EXIT_SUCCESS;
+  for (int DeviceId = 0; DeviceId < Count; ++DeviceId) {
+CUdevice Device;
+if (CUresult Err = cuDeviceGet(&Device, DeviceId))
+  return handleError(Err);
+
+int32_t Major, Minor;
+if (CUresult Err = cuDeviceGetAttribute(
+&Major, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR, Device))
+  return handleError(Err);
+if (CUresult Err = cuDeviceGetAttribute(
+&Minor, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR, Device))
+  return handleError(Err);
+
+printf("sm_%d%d\n", Major, Minor);
+  }
+  return EXIT_SUCCESS;
+}
+
+#endif
Index: clang/tools/nvptx-arch/CMakeLists.txt
===
--- /dev/null
+++ clang/tools/nvptx-arch/CMakeLists.txt
@@ -0,0 +1,28 @@
+# //======//
+# //
+# // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+# // See https://llvm.org/LICENSE.txt for details.
+# // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+# //
+# //======//
+
+
+# TODO: This is deprecated. Since CMake 3.17 we can use FindCUDAToolkit instead.
+find_package(CUDA QUIET)
+find_library(cuda-library NAMES cuda PATHS /lib64)
+if (NOT cuda-library AND CUDA_FOUND)
+  get_filename_component(CUDA_LIBDIR "${CUDA_cudart_static_LIBRARY}" DIRECTORY)
+  find_library(cuda-library NAMES cuda HINTS "${CUDA_LIBDIR}/stubs")
+endif()
+
+if (NOT CUDA_FOUND OR NOT cuda-library)
+  message(STATUS "Not building nvptx-arch: cuda runtime not found")
+  return()
+endif()
+
+add_clang_tool(nvptx-arch NVPTXArch.cpp)
+
+set_target_properties(nvptx-arch PROPERTIES INSTALL_RPATH_USE_LINK_PATH ON)
+target_include_directories(nvptx-arch PRIVATE ${CUDA_INCLUDE_DIRS})
+
+clang_target_link_libraries(nvptx-arch PRIVATE ${cuda-library})
Index: clang/tools/CMakeLists.txt
===
--- clang/tools/CMakeLists.txt
+++ clang/tools/CMakeLists.txt
@@ -50,3 +50,4 @@
 add_clang_subdirectory(libclang)
 
 add_clang_subdirectory(amdgpu-arch)
+add_clang_subdirectory(nvptx-arch)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D137107: Allow MS extension: support of constexpr with __declspec(dllimport).

2022-12-21 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added inline comments.



Comment at: clang/lib/CodeGen/CodeGenModule.cpp:5006
+if (NeedsGlobalCtor || NeedsGlobalDtor)
+  DelayedCXXInitPosition[D] = ~0U;
+  } else {

zahiraam wrote:
> efriedma wrote:
> > zahiraam wrote:
> > > Do you agree this should be done only when one of those flags is on?
> > Yes, that's fine; I wasn't really paying close attention to the exact code. 
> >  Just wanted to make the point about the structure of the if statements, 
> > and code was the easiest way to explain it.
> > 
> > Maybe the outer if statement should actually be `if (isStaticInit(D, 
> > getLangOpts()) && NeedsGlobalCtor) {`.
> > 
> > On a related note, we might want to avoid the name "ctor", in case that 
> > accidentally conflicts with some user code; an "__"-prefixed name would be 
> > appropriate.
> >> Maybe the outer if statement should actually be if (isStaticInit(D, 
> >> getLangOpts()) && NeedsGlobalCtor) {
> Not sure about that! There are cases where (isStaticInit(D, getLangOpts())) = 
> true and NeedsGlobalCtor=false, but NeedsGlobalDtor=true. In which case a 
> __dtor needs to be emitted, no?
> 
> Writing the condition as you are proposing would actually not get me into the 
> body to emit the __dtor. Is that what we want?
EmitCXXGlobalVarDeclInitFunc should be able to handle that case.

Looking again, I'm a little concerned that in the isStaticInit() case, we're 
skipping a bunch of the logic in EmitCXXGlobalVarDeclInitFunc. EmitCXXCtorInit 
handles the basic cases correctly, but there are a lot of special cases in 
EmitCXXGlobalVarDeclInitFunc.


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

https://reviews.llvm.org/D137107

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


[PATCH] D137838: [Support] Move TargetParsers to new component

2022-12-21 Thread Francesco Petrogalli via Phabricator via cfe-commits
fpetrogalli added a comment.

In D137838#4010987 , @dblaikie wrote:

> This has introduced a circular dependency due to the forwarding header 
> (forwarding header depends on new lib, new lib depends on support, where the 
> forwarding header is). Generally this wouldn't be acceptable (& I'd suggest 
> the patch be reverted on that basis) though I understand this is a 
> complicated migration - what's the timeline for correcting this issue?

IIUC, the fix here would be to remove the forwarding headers, right?

Francesco


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137838

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


[PATCH] D127812: [AArch64] FMV support and necessary target features dependencies.

2022-12-21 Thread Pavel Iliin via Phabricator via cfe-commits
ilinpv added a comment.

In D127812#4010993 , @hctim wrote:

> Hmm, not exactly sure what's going on with the `could NOT find Threads` 
> there. A quick googling seems to point to pthreads.so not being in the right 
> places, but I don't think the buildbot does anything special. Do your regular 
> builds with `-DLLVM_ENABLE_PROJECTS="compiler_rt;clang;lld"` work?
>
> When you say that it looks fine locally, is that from your own checkout but 
> using `-DLLVM_USE_SANITIZER=Memory`? First thing to check is that you do end 
> up with MSan in the test (in particular the clang binary that's being 
> produced), which you can do by `nm bin/clang-16 | grep __msan_init`.

Regular builds works fine for me, pthreads located here 
"/lib/x86_64-linux-gnu/libpthread.so" 
"/usr/lib/x86_64-linux-gnu/libpthread.so". Enabling 
"-DLLVM_USE_SANITIZER=Memory" resulted in many "WARNING: MemorySanitizer: 
use-of-uninitialized-value" on tblgen like:

  cd /data/ReleasesToCommit/llvm-project/build && 
/data/ReleasesToCommit/llvm-project/build/bin/llvm-tblgen -gen-intrinsic-enums 
-intrinsic-prefix=s390 -I 
/data/ReleasesToCommit/llvm-project/llvm/include/llvm/IR 
-I/data/ReleasesToCommit/llvm-project/build/include 
-I/data/ReleasesToCommit/llvm-project/llvm/include 
/data/ReleasesToCommit/llvm-project/llvm/include/llvm/IR/Intrinsics.td 
--write-if-changed -o include/llvm/IR/IntrinsicsS390.h -d 
include/llvm/IR/IntrinsicsS390.h.d
  [build] ==2441251==WARNING: MemorySanitizer: use-of-uninitialized-value


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127812

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


[PATCH] D138655: [clang-tidy] Fix `cppcoreguidelines-init-variables` for invalid vardecl

2022-12-21 Thread Nathan James via Phabricator via cfe-commits
njames93 added a comment.

In D138655#4007822 , @carlosgalvezp 
wrote:

> Now that I think a bit better about this I wonder - does it really make sense 
> that we increase the complexity of the check to cover for cases where code 
> does not compile? If it fails to include a header, there's many other things 
> that can possibly go wrong - should clang-tidy checks in general really be 
> defensive against that? @njames93 WDYT?

It's not a hard rule that we should be defensive against clang-tidy emitting 
false positives due to a previous compilation error. However for simple cases, 
like this, where its just ensuring a declaration is valid before we try to emit 
diagnostic, It does make sense to handle this.
With this change the main thing would be a little less noise while trying to 
debug the cause of the compilation error which is always a good thing.




Comment at: 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/init-variables.cpp:4-13
+// Header file error causes stl container variable to be invalid int vardecl
+#include "unknown.h" 
+// CHECK-MESSAGES: :[[@LINE-1]]:10: error: 'unknown.h' file not found 
[clang-diagnostic-error]
+
+namespace std {
+template 
+struct vector {

All this is unnecessary there is a much nicer way to test this, see below



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/init-variables.cpp:139-141
+  int a;
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: variable 'a' is not initialized 
[cppcoreguidelines-init-variables]
+  // CHECK-FIXES: {{^}}  int a = 0;{{$}}

This test line is not testing the behaviour described in this patch and can be 
removed.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/init-variables.cpp:144
+  // The stl object has been initialized
+  std::vector arr;
+  // CHECK-FIXES-NOT: {{^}}  std::vector arr = 0;{{$}}

Just use this and the declaration will be invalid and you can test the expected 
behaviour


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

https://reviews.llvm.org/D138655

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


[PATCH] D137517: [TargetParser] Generate the defs for RISCV CPUs using llvm-tblgen.

2022-12-21 Thread Francesco Petrogalli via Phabricator via cfe-commits
fpetrogalli updated this revision to Diff 484649.
fpetrogalli marked 5 inline comments as done.
fpetrogalli added a comment.

I submitted some of the cleanup suggested by @barannikov88 - thank you!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137517

Files:
  clang/lib/Basic/Targets/RISCV.cpp
  clang/lib/Driver/ToolChains/Arch/RISCV.cpp
  llvm/include/llvm/TargetParser/RISCVTargetParser.def
  llvm/include/llvm/TargetParser/RISCVTargetParser.h
  llvm/include/llvm/TargetParser/TargetParser.h
  llvm/lib/Target/RISCV/RISCV.td
  llvm/lib/Target/RISCV/RISCVISelLowering.h
  llvm/lib/TargetParser/CMakeLists.txt
  llvm/lib/TargetParser/RISCVTargetParser.cpp
  llvm/lib/TargetParser/TargetParser.cpp
  llvm/utils/TableGen/CMakeLists.txt
  llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
  llvm/utils/TableGen/TableGen.cpp
  llvm/utils/TableGen/TableGenBackends.h

Index: llvm/utils/TableGen/TableGenBackends.h
===
--- llvm/utils/TableGen/TableGenBackends.h
+++ llvm/utils/TableGen/TableGenBackends.h
@@ -94,7 +94,7 @@
 void EmitDirectivesDecl(RecordKeeper &RK, raw_ostream &OS);
 void EmitDirectivesImpl(RecordKeeper &RK, raw_ostream &OS);
 void EmitDXILOperation(RecordKeeper &RK, raw_ostream &OS);
-
+void EmitRISCVTargetDef(const RecordKeeper &RK, raw_ostream &OS);
 } // End llvm namespace
 
 #endif
Index: llvm/utils/TableGen/TableGen.cpp
===
--- llvm/utils/TableGen/TableGen.cpp
+++ llvm/utils/TableGen/TableGen.cpp
@@ -58,6 +58,7 @@
   GenDirectivesEnumDecl,
   GenDirectivesEnumImpl,
   GenDXILOperation,
+  GenRISCVTargetDef,
 };
 
 namespace llvm {
@@ -141,8 +142,9 @@
 clEnumValN(GenDirectivesEnumImpl, "gen-directive-impl",
"Generate directive related implementation code"),
 clEnumValN(GenDXILOperation, "gen-dxil-operation",
-   "Generate DXIL operation information")));
-
+   "Generate DXIL operation information"),
+clEnumValN(GenRISCVTargetDef, "gen-riscv-target-def",
+   "Generate the list of CPU for RISCV")));
 cl::OptionCategory PrintEnumsCat("Options for -print-enums");
 cl::opt Class("class", cl::desc("Print Enum list for this class"),
cl::value_desc("class name"),
@@ -278,6 +280,9 @@
   case GenDXILOperation:
 EmitDXILOperation(Records, OS);
 break;
+  case GenRISCVTargetDef:
+EmitRISCVTargetDef(Records, OS);
+break;
   }
 
   return false;
Index: llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
===
--- /dev/null
+++ llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
@@ -0,0 +1,61 @@
+//===- RISCVTargetDefEmitter.cpp - Generate lists of RISCV CPUs ---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This tablegen backend emits the include file needed by the target
+// parser to parse the RISC-V CPUs.
+//
+//===--===//
+
+#include "llvm/TableGen/Record.h"
+
+namespace llvm {
+
+static std::string getEnumFeatures(Record &Rec) {
+  std::vector Features = Rec.getValueAsListOfDefs("Features");
+  if (find_if(Features, [](Record *R) {
+return R->getName() == "Feature64Bit";
+  }) != Features.end())
+return "FK_64BIT";
+
+  return "FK_NONE";
+}
+
+void EmitRISCVTargetDef(const RecordKeeper &RK, raw_ostream &OS) {
+  const auto &Map = RK.getDefs();
+
+  OS << "#ifndef PROC\n"
+ << "#define PROC(ENUM, NAME, FEATURES, DEFAULT_MARCH)\n"
+ << "#endif\n\n";
+
+  OS << "PROC(INVALID, {\"invalid\"}, FK_INVALID, {\"\"})\n";
+  // Iterate on all definition records.
+  for (const auto &Def : Map) {
+const auto &Record = Def.second;
+if (Record->isSubClassOf("RISCVProcessorModelPROC"))
+  OS << "PROC(" << Record->getName() << ", "
+ << "{\"" << Record->getValueAsString("Name") << "\"},"
+ << getEnumFeatures(*Record) << ", "
+ << "{\"" << Record->getValueAsString("DefaultMarch") << "\"})\n";
+  }
+  OS << "\n#undef PROC\n";
+  OS << "\n";
+  OS << "#ifndef TUNE_PROC\n"
+ << "#define TUNE_PROC(ENUM, NAME)\n"
+ << "#endif\n\n";
+  OS << "TUNE_PROC(GENERIC, \"generic\")\n";
+  for (const auto &Def : Map) {
+const auto &Record = Def.second;
+if (Record->isSubClassOf("RISCVProcessorModelTUNE_PROC"))
+  OS << "TUNE_PROC(" << Record->getName() << ", "
+ << "\"" << Record->getValueAsString("Name") << "\")\n";
+  }
+
+  OS << "\n#undef TUNE_PROC\n";
+}
+
+} // namespace llvm
Index: llvm/utils/TableGen/CMakeLists.txt

[PATCH] D137517: [TargetParser] Generate the defs for RISCV CPUs using llvm-tblgen.

2022-12-21 Thread Francesco Petrogalli via Phabricator via cfe-commits
fpetrogalli added inline comments.



Comment at: llvm/utils/TableGen/RISCVTargetDefEmitter.cpp:15
+#include "llvm/TableGen/Record.h"
+#include 
+namespace llvm {

barannikov88 wrote:
>  [[ 
> https://llvm.org/docs/CodingStandards.html#include-iostream-is-forbidden | is 
> forbidden ]] by the coding standards.
> 
Ops - that was a leftover for my nasty debugging session :)



Comment at: llvm/utils/TableGen/RISCVTargetDefEmitter.cpp:16
+#include 
+namespace llvm {
+

barannikov88 wrote:
> This [[ 
> https://llvm.org/docs/CodingStandards.html#use-namespace-qualifiers-to-implement-previously-declared-functions
>  | should be ]] `using namespace llvm;`
Hum, if I do this, I get:

```
Undefined symbols for architecture arm64:
  "llvm::EmitRISCVTargetDef(llvm::RecordKeeper&, llvm::raw_ostream&)", 
referenced from:
  (anonymous namespace)::LLVMTableGenMain(llvm::raw_ostream&, 
llvm::RecordKeeper&) in TableGen.cpp.o
ld: symbol(s) not found for architecture arm64
```

It is a bit surprising because the linking command has 
`utils/TableGen/CMakeFiles/llvm-tblgen.dir/RISCVTargetDefEmitter.cpp.o` into 
it... Some of the files in this folder do not use the convention you pointed 
at, it it OK if I live it as it is?



Comment at: llvm/utils/TableGen/RISCVTargetDefEmitter.cpp:28
+
+void EmitRISCVTargetDef(RecordKeeper &RK, raw_ostream &OS) {
+  const auto &Map = RK.getDefs();

barannikov88 wrote:
> This function does not seem to mutate RecordKeeper, so it should be `const`.
Done, however none of the other "emitters" in `TableGenBackends.h` mark the 
record keeper as const...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137517

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


[PATCH] D127812: [AArch64] FMV support and necessary target features dependencies.

2022-12-21 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added a comment.

In D127812#4011372 , @ilinpv wrote:

> Regular builds works fine for me, pthreads located here 
> "/lib/x86_64-linux-gnu/libpthread.so" 
> "/usr/lib/x86_64-linux-gnu/libpthread.so". Enabling 
> "-DLLVM_USE_SANITIZER=Memory" resulted in many "WARNING: MemorySanitizer: 
> use-of-uninitialized-value" on tblgen like:
>
>   cd /data/ReleasesToCommit/llvm-project/build && 
> /data/ReleasesToCommit/llvm-project/build/bin/llvm-tblgen 
> -gen-intrinsic-enums -intrinsic-prefix=s390 -I 
> /data/ReleasesToCommit/llvm-project/llvm/include/llvm/IR 
> -I/data/ReleasesToCommit/llvm-project/build/include 
> -I/data/ReleasesToCommit/llvm-project/llvm/include 
> /data/ReleasesToCommit/llvm-project/llvm/include/llvm/IR/Intrinsics.td 
> --write-if-changed -o include/llvm/IR/IntrinsicsS390.h -d 
> include/llvm/IR/IntrinsicsS390.h.d
>   [build] ==2441251==WARNING: MemorySanitizer: use-of-uninitialized-value

Yeah that's a false-positive because of bad-ordering. MSan is much tricker 
because it requires an instrumented libcxx. If you can't use the buildscript, 
an MVP for the right ordering should be something like:

1. Build a new clang.

  $ cd /tmp/1/
  $ cmake \
  -DLLVM_ENABLE_PROJECTS="clang;compiler-rt;lld" \
  -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi" \
  -DCMAKE_C_COMPILER=clang \
  -DCMAKE_CXX_COMPILER=clang++ \
  -GNinja \
  -DCMAKE_BUILD_TYPE=Release \
  -DLLVM_USE_LINKER=lld \
  -DCMAKE_C_FLAGS="-Wall" \
  -DCMAKE_CXX_FLAGS="-Wall" \
  /path/to/llvm/llvm
  $ ninja clang lld compiler-rt llvm-symbolizer



2. Build a sanitizer libcxx.

  $ cd /tmp/2
  $ cmake \
  -DCMAKE_C_COMPILER=/tmp/1/bin/clang \
  -DCMAKE_CXX_COMPILER=/tmp/1/bin/clang++ \
  -GNinja \
  -DLLVM_USE_SANITIZER=Memory \
  -DCMAKE_BUILD_TYPE=Release \
  -DLLVM_ENABLE_ASSERTIONS=ON \
  -DLLVM_ENABLE_RUNTIMES="'libcxx;libcxxabi'" \
  -DLLVM_USE_LINKER="'lld'" \
  /path/to/llvm/runtimes/ # < Make sure this is *runtimes*, not llvm.
  $ ninja cxx cxxabi



3. Build a msan-ified clang, and use the libcxx from step 2.

  $ cd /tmp/3
  $ cat .cmake_script.sh
  #!/bin/bash -e
  
  LDFLAGS="-lc++abi"
  LDFLAGS="$LDFLAGS -Wl,--rpath=/tmp/2/lib" # < use the instrumented libcxx 
from step 2
  LDFLAGS="$LDFLAGS -L/tmp/2/lib"
  
  CFLAGS="$LDFLAGS"
  CFLAGS="$CFLAGS -fsanitize=memory"
  CFLAGS="$CFLAGS -nostdinc++"
  CFLAGS="$CFLAGS -isystem /tmp/2/include" # < use the instrumented libcxx 
from step 2
  CFLAGS="$CFLAGS -isystem /tmp/2/include/c++/v1"
  CFLAGS="$CFLAGS -w"
  CFLAGS="$CFLAGS -fsanitize-memory-use-after-dtor 
-fsanitize-memory-param-retval"
  
  USE_SANITIZER="Memory"
  # USE_SANITIZER="MemoryWithOrigins"  # <---+-- uncomment 
these and comment the USE_SANITIZER="Memory" above to get track-origins.
  # CFLAGS="$CFLAGS -fsanitize-memory-track-origins=2"  # <--+
  
  cmake \
  -DCMAKE_C_COMPILER=/tmp/1/bin/clang \
  -DCMAKE_CXX_COMPILER=/tmp/1/bin/clang++ \
  -DLLVM_ENABLE_LIBCXX=ON \
  -GNinja \
  -DLLVM_USE_SANITIZER="$USE_SANITIZER" \
  -DCMAKE_BUILD_TYPE=Release \
  -DLLVM_ENABLE_ASSERTIONS=ON \
  -DCMAKE_C_FLAGS="$CFLAGS" \
  -DCMAKE_CXX_FLAGS="$CFLAGS" \
  -DCMAKE_EXE_LINKER_FLAGS="$LDFLAGS" \
  -DLLVM_ENABLE_PROJECTS="clang;lld;clang-tools-extra" \
  -DLLVM_USE_LINKER="lld" \
  /path/to/llvm/llvm
  $ . .cmake_script.sh
  $ ninja clang lld
  $ ninja check-clang check-llvm # <- finally, run your tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127812

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


[PATCH] D140315: [AMDGCN] Update search path for device libraries

2022-12-21 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

files under 
clang/test/Driver/Inputs/rocm_resource_dir/lib/amdgcn/bitcode-no-abi-ver seem 
not used.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140315

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


[PATCH] D137517: [TargetParser] Generate the defs for RISCV CPUs using llvm-tblgen.

2022-12-21 Thread Sergei Barannikov via Phabricator via cfe-commits
barannikov88 added inline comments.



Comment at: llvm/utils/TableGen/RISCVTargetDefEmitter.cpp:16
+#include 
+namespace llvm {
+

fpetrogalli wrote:
> barannikov88 wrote:
> > This [[ 
> > https://llvm.org/docs/CodingStandards.html#use-namespace-qualifiers-to-implement-previously-declared-functions
> >  | should be ]] `using namespace llvm;`
> Hum, if I do this, I get:
> 
> ```
> Undefined symbols for architecture arm64:
>   "llvm::EmitRISCVTargetDef(llvm::RecordKeeper&, llvm::raw_ostream&)", 
> referenced from:
>   (anonymous namespace)::LLVMTableGenMain(llvm::raw_ostream&, 
> llvm::RecordKeeper&) in TableGen.cpp.o
> ld: symbol(s) not found for architecture arm64
> ```
> 
> It is a bit surprising because the linking command has 
> `utils/TableGen/CMakeFiles/llvm-tblgen.dir/RISCVTargetDefEmitter.cpp.o` into 
> it... Some of the files in this folder do not use the convention you pointed 
> at, it it OK if I live it as it is?
Right, after `using namespace llvm` you have to write
`llvm::EmitRISCVTargetDef` with explicit `llvm::` qualification. This is the 
whole point of this guideline :)
Please see the [[ 
https://llvm.org/docs/CodingStandards.html#use-namespace-qualifiers-to-implement-previously-declared-functions
 | link ]].



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137517

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


[PATCH] D137517: [TargetParser] Generate the defs for RISCV CPUs using llvm-tblgen.

2022-12-21 Thread Francesco Petrogalli via Phabricator via cfe-commits
fpetrogalli marked an inline comment as done.
fpetrogalli added inline comments.



Comment at: llvm/lib/TargetParser/CMakeLists.txt:29
+# LLVMTargetParser. See https://stackoverflow.com/a/25681179
+target_include_directories(LLVMTargetParser PUBLIC 
$)

barannikov88 wrote:
> Will it work if RISC-V target is not compiled-in?
> This does not strictly add a cyclic dependency, but it would still be nice to 
> avoid dependency on higher-level components.
> Is it possible / reasonable to extract the part of the RISCV.td that relates 
> to this component and put it separate td file in this directory? Or is it 
> tightly coupled with the rest of the target description?
> 
> Will it work if RISC-V target is not compiled-in?

This line worked, so yes

```
cmake ../llvm-project/llvm -DLLVM_ENABLE_PROJECTS=clang 
-DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -GNinja 
-DLLVM_TARGETS_TO_BUILD="AArch64;AMDGPU;ARM;AVR;BPF;Hexagon;Lanai;Mips;MSP430;NVPTX;PowerPC;Sparc;SystemZ;VE;WebAssembly;X86;XCore"
```


> This does not strictly add a cyclic dependency, but it would still be nice to 
> avoid dependency on higher-level components.
> Is it possible / reasonable to extract the part of the RISCV.td that relates 
> to this component and put it separate td file in this directory? Or is it 
> tightly coupled with the rest of the target description?
> 

Hum - the content of RISCV.td is central in `llvm/lib/Target/RISCV/`. The only 
way I can see we can put a td file in this folder is by duplicating the content 
that we use from `RISCV.td`... That however would mean missing the point of 
this patch though, as the idea is to have centralised unique source of 
information.




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137517

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


[PATCH] D137232: [clang][Interp] Support inc/dec operators on pointers

2022-12-21 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik accepted this revision.
shafik added a comment.

LGTM


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

https://reviews.llvm.org/D137232

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


[PATCH] D137517: [TargetParser] Generate the defs for RISCV CPUs using llvm-tblgen.

2022-12-21 Thread Francesco Petrogalli via Phabricator via cfe-commits
fpetrogalli marked an inline comment as done.
fpetrogalli added inline comments.



Comment at: llvm/utils/TableGen/RISCVTargetDefEmitter.cpp:52
+  for (auto &Def : Map) {
+const auto &Record = Def.second;
+if (Record->isSubClassOf("RISCVProcessorModelTUNE_PROC"))

barannikov88 wrote:
> Same for the loop above.
```
/Users/fpetrogalli/projects/cpu-defs/upstream/llvm-project/llvm/utils/TableGen/RISCVTargetDefEmitter.cpp:38:17:
 error: variable 'Record' with type 'const auto *' has incompatible initializer 
of type 'const std::unique_ptr'
const auto *Record = Def.second;
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137517

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


[PATCH] D137517: [TargetParser] Generate the defs for RISCV CPUs using llvm-tblgen.

2022-12-21 Thread Francesco Petrogalli via Phabricator via cfe-commits
fpetrogalli updated this revision to Diff 484654.
fpetrogalli marked an inline comment as done.
fpetrogalli added a comment.

ops - this was wrong:

  
/Users/fpetrogalli/projects/cpu-defs/upstream/llvm-project/llvm/utils/TableGen/RISCVTargetDefEmitter.cpp:38:17:
 error: variable 'Record' with type 'const auto *' has incompatible initializer 
of type 'const std::unique_ptr'
  const auto *Record = Def.second;

I'll revert it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137517

Files:
  clang/lib/Basic/Targets/RISCV.cpp
  clang/lib/Driver/ToolChains/Arch/RISCV.cpp
  llvm/include/llvm/TargetParser/RISCVTargetParser.def
  llvm/include/llvm/TargetParser/RISCVTargetParser.h
  llvm/include/llvm/TargetParser/TargetParser.h
  llvm/lib/Target/RISCV/RISCV.td
  llvm/lib/Target/RISCV/RISCVISelLowering.h
  llvm/lib/TargetParser/CMakeLists.txt
  llvm/lib/TargetParser/RISCVTargetParser.cpp
  llvm/lib/TargetParser/TargetParser.cpp
  llvm/utils/TableGen/CMakeLists.txt
  llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
  llvm/utils/TableGen/TableGen.cpp
  llvm/utils/TableGen/TableGenBackends.h

Index: llvm/utils/TableGen/TableGenBackends.h
===
--- llvm/utils/TableGen/TableGenBackends.h
+++ llvm/utils/TableGen/TableGenBackends.h
@@ -94,7 +94,7 @@
 void EmitDirectivesDecl(RecordKeeper &RK, raw_ostream &OS);
 void EmitDirectivesImpl(RecordKeeper &RK, raw_ostream &OS);
 void EmitDXILOperation(RecordKeeper &RK, raw_ostream &OS);
-
+void EmitRISCVTargetDef(const RecordKeeper &RK, raw_ostream &OS);
 } // End llvm namespace
 
 #endif
Index: llvm/utils/TableGen/TableGen.cpp
===
--- llvm/utils/TableGen/TableGen.cpp
+++ llvm/utils/TableGen/TableGen.cpp
@@ -58,6 +58,7 @@
   GenDirectivesEnumDecl,
   GenDirectivesEnumImpl,
   GenDXILOperation,
+  GenRISCVTargetDef,
 };
 
 namespace llvm {
@@ -141,8 +142,9 @@
 clEnumValN(GenDirectivesEnumImpl, "gen-directive-impl",
"Generate directive related implementation code"),
 clEnumValN(GenDXILOperation, "gen-dxil-operation",
-   "Generate DXIL operation information")));
-
+   "Generate DXIL operation information"),
+clEnumValN(GenRISCVTargetDef, "gen-riscv-target-def",
+   "Generate the list of CPU for RISCV")));
 cl::OptionCategory PrintEnumsCat("Options for -print-enums");
 cl::opt Class("class", cl::desc("Print Enum list for this class"),
cl::value_desc("class name"),
@@ -278,6 +280,9 @@
   case GenDXILOperation:
 EmitDXILOperation(Records, OS);
 break;
+  case GenRISCVTargetDef:
+EmitRISCVTargetDef(Records, OS);
+break;
   }
 
   return false;
Index: llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
===
--- /dev/null
+++ llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
@@ -0,0 +1,61 @@
+//===- RISCVTargetDefEmitter.cpp - Generate lists of RISCV CPUs ---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This tablegen backend emits the include file needed by the target
+// parser to parse the RISC-V CPUs.
+//
+//===--===//
+
+#include "llvm/TableGen/Record.h"
+
+namespace llvm {
+
+static std::string getEnumFeatures(Record &Rec) {
+  std::vector Features = Rec.getValueAsListOfDefs("Features");
+  if (find_if(Features, [](Record *R) {
+return R->getName() == "Feature64Bit";
+  }) != Features.end())
+return "FK_64BIT";
+
+  return "FK_NONE";
+}
+
+void EmitRISCVTargetDef(const RecordKeeper &RK, raw_ostream &OS) {
+  const auto &Map = RK.getDefs();
+
+  OS << "#ifndef PROC\n"
+ << "#define PROC(ENUM, NAME, FEATURES, DEFAULT_MARCH)\n"
+ << "#endif\n\n";
+
+  OS << "PROC(INVALID, {\"invalid\"}, FK_INVALID, {\"\"})\n";
+  // Iterate on all definition records.
+  for (const auto &Def : Map) {
+const auto *Record = Def.second;
+if (Record->isSubClassOf("RISCVProcessorModelPROC"))
+  OS << "PROC(" << Record->getName() << ", "
+ << "{\"" << Record->getValueAsString("Name") << "\"},"
+ << getEnumFeatures(*Record) << ", "
+ << "{\"" << Record->getValueAsString("DefaultMarch") << "\"})\n";
+  }
+  OS << "\n#undef PROC\n";
+  OS << "\n";
+  OS << "#ifndef TUNE_PROC\n"
+ << "#define TUNE_PROC(ENUM, NAME)\n"
+ << "#endif\n\n";
+  OS << "TUNE_PROC(GENERIC, \"generic\")\n";
+  for (const auto &Def : Map) {
+const auto *Record = Def.second;
+if (Record->isSubClassOf("RISCVProcessorModelTUNE_PROC"))
+  OS 

[PATCH] D137517: [TargetParser] Generate the defs for RISCV CPUs using llvm-tblgen.

2022-12-21 Thread Francesco Petrogalli via Phabricator via cfe-commits
fpetrogalli updated this revision to Diff 484655.
fpetrogalli added a comment.

Restore the following...

  -const auto *Record = Def.second;
  +const auto &Record = Def.second;

... to prevent this error:

  /<...>/llvm-project/llvm/utils/TableGen/RISCVTargetDefEmitter.cpp:38:17: 
error: variable 'Record' with type 'const auto *' has incompatible initializer 
of type 'const std::unique_ptr'
  const auto *Record = Def.second;


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137517

Files:
  clang/lib/Basic/Targets/RISCV.cpp
  clang/lib/Driver/ToolChains/Arch/RISCV.cpp
  llvm/include/llvm/TargetParser/RISCVTargetParser.def
  llvm/include/llvm/TargetParser/RISCVTargetParser.h
  llvm/include/llvm/TargetParser/TargetParser.h
  llvm/lib/Target/RISCV/RISCV.td
  llvm/lib/Target/RISCV/RISCVISelLowering.h
  llvm/lib/TargetParser/CMakeLists.txt
  llvm/lib/TargetParser/RISCVTargetParser.cpp
  llvm/lib/TargetParser/TargetParser.cpp
  llvm/utils/TableGen/CMakeLists.txt
  llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
  llvm/utils/TableGen/TableGen.cpp
  llvm/utils/TableGen/TableGenBackends.h

Index: llvm/utils/TableGen/TableGenBackends.h
===
--- llvm/utils/TableGen/TableGenBackends.h
+++ llvm/utils/TableGen/TableGenBackends.h
@@ -94,7 +94,7 @@
 void EmitDirectivesDecl(RecordKeeper &RK, raw_ostream &OS);
 void EmitDirectivesImpl(RecordKeeper &RK, raw_ostream &OS);
 void EmitDXILOperation(RecordKeeper &RK, raw_ostream &OS);
-
+void EmitRISCVTargetDef(const RecordKeeper &RK, raw_ostream &OS);
 } // End llvm namespace
 
 #endif
Index: llvm/utils/TableGen/TableGen.cpp
===
--- llvm/utils/TableGen/TableGen.cpp
+++ llvm/utils/TableGen/TableGen.cpp
@@ -58,6 +58,7 @@
   GenDirectivesEnumDecl,
   GenDirectivesEnumImpl,
   GenDXILOperation,
+  GenRISCVTargetDef,
 };
 
 namespace llvm {
@@ -141,8 +142,9 @@
 clEnumValN(GenDirectivesEnumImpl, "gen-directive-impl",
"Generate directive related implementation code"),
 clEnumValN(GenDXILOperation, "gen-dxil-operation",
-   "Generate DXIL operation information")));
-
+   "Generate DXIL operation information"),
+clEnumValN(GenRISCVTargetDef, "gen-riscv-target-def",
+   "Generate the list of CPU for RISCV")));
 cl::OptionCategory PrintEnumsCat("Options for -print-enums");
 cl::opt Class("class", cl::desc("Print Enum list for this class"),
cl::value_desc("class name"),
@@ -278,6 +280,9 @@
   case GenDXILOperation:
 EmitDXILOperation(Records, OS);
 break;
+  case GenRISCVTargetDef:
+EmitRISCVTargetDef(Records, OS);
+break;
   }
 
   return false;
Index: llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
===
--- /dev/null
+++ llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
@@ -0,0 +1,61 @@
+//===- RISCVTargetDefEmitter.cpp - Generate lists of RISCV CPUs ---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This tablegen backend emits the include file needed by the target
+// parser to parse the RISC-V CPUs.
+//
+//===--===//
+
+#include "llvm/TableGen/Record.h"
+
+namespace llvm {
+
+static std::string getEnumFeatures(Record &Rec) {
+  std::vector Features = Rec.getValueAsListOfDefs("Features");
+  if (find_if(Features, [](Record *R) {
+return R->getName() == "Feature64Bit";
+  }) != Features.end())
+return "FK_64BIT";
+
+  return "FK_NONE";
+}
+
+void EmitRISCVTargetDef(const RecordKeeper &RK, raw_ostream &OS) {
+  const auto &Map = RK.getDefs();
+
+  OS << "#ifndef PROC\n"
+ << "#define PROC(ENUM, NAME, FEATURES, DEFAULT_MARCH)\n"
+ << "#endif\n\n";
+
+  OS << "PROC(INVALID, {\"invalid\"}, FK_INVALID, {\"\"})\n";
+  // Iterate on all definition records.
+  for (const auto &Def : Map) {
+const auto &Record = Def.second;
+if (Record->isSubClassOf("RISCVProcessorModelPROC"))
+  OS << "PROC(" << Record->getName() << ", "
+ << "{\"" << Record->getValueAsString("Name") << "\"},"
+ << getEnumFeatures(*Record) << ", "
+ << "{\"" << Record->getValueAsString("DefaultMarch") << "\"})\n";
+  }
+  OS << "\n#undef PROC\n";
+  OS << "\n";
+  OS << "#ifndef TUNE_PROC\n"
+ << "#define TUNE_PROC(ENUM, NAME)\n"
+ << "#endif\n\n";
+  OS << "TUNE_PROC(GENERIC, \"generic\")\n";
+  for (const auto &Def : Map) {
+const auto &Record = Def.second;
+if (Record->isSubClassOf("RISCVProcessorModelTUNE_PROC"))
+

[PATCH] D135750: [clang][Interp] Track initialization state of local variables

2022-12-21 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added inline comments.



Comment at: clang/lib/AST/Interp/Interp.h:918
 return false;
+  if (!Ptr.isRoot())
+Ptr.initialize();

tbaeder wrote:
> shafik wrote:
> > Can you explain what is going on here? Why do we need to initialize if it 
> > is not root?
> Root means that `Base == 0`, so it cannot have a `InlineDescriptor` before 
> the `Base` offset. That is mainly the case for global variables.
Can we add a comment that explains this a little better? I still don't get the 
significance, so I definitely missing something.

Also, why do we initialized before the store? 


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

https://reviews.llvm.org/D135750

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


[PATCH] D137070: [clang][Interp] Support destructors

2022-12-21 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik accepted this revision.
shafik added a comment.
This revision is now accepted and ready to land.

LGTM


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

https://reviews.llvm.org/D137070

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


[PATCH] D138392: clang/HIP: Fix broken implementations of __make_mantissa* functions

2022-12-21 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl accepted this revision.
yaxunl added a comment.
This revision is now accepted and ready to land.

LGTM. Thanks.

It seems gcc assumes the argument to nan is nonnull 
(https://godbolt.org/z/xzb8T6Gon), so we can assume that too.


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

https://reviews.llvm.org/D138392

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


[PATCH] D137517: [TargetParser] Generate the defs for RISCV CPUs using llvm-tblgen.

2022-12-21 Thread Francesco Petrogalli via Phabricator via cfe-commits
fpetrogalli updated this revision to Diff 484658.
fpetrogalli marked an inline comment as done.
fpetrogalli added a comment.

Remove `RISCVTargetParser.def` from the module map.

Follow the guidelines on  using namespace llvm 
.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137517

Files:
  clang/lib/Basic/Targets/RISCV.cpp
  clang/lib/Driver/ToolChains/Arch/RISCV.cpp
  llvm/include/llvm/TargetParser/RISCVTargetParser.def
  llvm/include/llvm/TargetParser/RISCVTargetParser.h
  llvm/include/llvm/TargetParser/TargetParser.h
  llvm/include/llvm/module.modulemap
  llvm/lib/Target/RISCV/RISCV.td
  llvm/lib/Target/RISCV/RISCVISelLowering.h
  llvm/lib/TargetParser/CMakeLists.txt
  llvm/lib/TargetParser/RISCVTargetParser.cpp
  llvm/lib/TargetParser/TargetParser.cpp
  llvm/utils/TableGen/CMakeLists.txt
  llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
  llvm/utils/TableGen/TableGen.cpp
  llvm/utils/TableGen/TableGenBackends.h

Index: llvm/utils/TableGen/TableGenBackends.h
===
--- llvm/utils/TableGen/TableGenBackends.h
+++ llvm/utils/TableGen/TableGenBackends.h
@@ -94,7 +94,7 @@
 void EmitDirectivesDecl(RecordKeeper &RK, raw_ostream &OS);
 void EmitDirectivesImpl(RecordKeeper &RK, raw_ostream &OS);
 void EmitDXILOperation(RecordKeeper &RK, raw_ostream &OS);
-
+void EmitRISCVTargetDef(const RecordKeeper &RK, raw_ostream &OS);
 } // End llvm namespace
 
 #endif
Index: llvm/utils/TableGen/TableGen.cpp
===
--- llvm/utils/TableGen/TableGen.cpp
+++ llvm/utils/TableGen/TableGen.cpp
@@ -58,6 +58,7 @@
   GenDirectivesEnumDecl,
   GenDirectivesEnumImpl,
   GenDXILOperation,
+  GenRISCVTargetDef,
 };
 
 namespace llvm {
@@ -141,8 +142,9 @@
 clEnumValN(GenDirectivesEnumImpl, "gen-directive-impl",
"Generate directive related implementation code"),
 clEnumValN(GenDXILOperation, "gen-dxil-operation",
-   "Generate DXIL operation information")));
-
+   "Generate DXIL operation information"),
+clEnumValN(GenRISCVTargetDef, "gen-riscv-target-def",
+   "Generate the list of CPU for RISCV")));
 cl::OptionCategory PrintEnumsCat("Options for -print-enums");
 cl::opt Class("class", cl::desc("Print Enum list for this class"),
cl::value_desc("class name"),
@@ -278,6 +280,9 @@
   case GenDXILOperation:
 EmitDXILOperation(Records, OS);
 break;
+  case GenRISCVTargetDef:
+EmitRISCVTargetDef(Records, OS);
+break;
   }
 
   return false;
Index: llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
===
--- /dev/null
+++ llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
@@ -0,0 +1,60 @@
+//===- RISCVTargetDefEmitter.cpp - Generate lists of RISCV CPUs ---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This tablegen backend emits the include file needed by the target
+// parser to parse the RISC-V CPUs.
+//
+//===--===//
+
+#include "TableGenBackends.h"
+#include "llvm/TableGen/Record.h"
+
+using namespace llvm;
+
+static std::string getEnumFeatures(Record &Rec) {
+  std::vector Features = Rec.getValueAsListOfDefs("Features");
+  if (find_if(Features, [](Record *R) {
+return R->getName() == "Feature64Bit";
+  }) != Features.end())
+return "FK_64BIT";
+
+  return "FK_NONE";
+}
+
+void llvm::EmitRISCVTargetDef(const RecordKeeper &RK, raw_ostream &OS) {
+  const auto &Map = RK.getDefs();
+
+  OS << "#ifndef PROC\n"
+ << "#define PROC(ENUM, NAME, FEATURES, DEFAULT_MARCH)\n"
+ << "#endif\n\n";
+
+  OS << "PROC(INVALID, {\"invalid\"}, FK_INVALID, {\"\"})\n";
+  // Iterate on all definition records.
+  for (const auto &Def : Map) {
+const auto &Record = Def.second;
+if (Record->isSubClassOf("RISCVProcessorModelPROC"))
+  OS << "PROC(" << Record->getName() << ", "
+ << "{\"" << Record->getValueAsString("Name") << "\"},"
+ << getEnumFeatures(*Record) << ", "
+ << "{\"" << Record->getValueAsString("DefaultMarch") << "\"})\n";
+  }
+  OS << "\n#undef PROC\n";
+  OS << "\n";
+  OS << "#ifndef TUNE_PROC\n"
+ << "#define TUNE_PROC(ENUM, NAME)\n"
+ << "#endif\n\n";
+  OS << "TUNE_PROC(GENERIC, \"generic\")\n";
+  for (const auto &Def : Map) {
+const auto &Record = Def.second;
+if (Record->isSubClassOf("RISCVProcessorModelTUNE_PROC"))
+  OS << "TUNE_PROC

[PATCH] D137517: [TargetParser] Generate the defs for RISCV CPUs using llvm-tblgen.

2022-12-21 Thread Sergei Barannikov via Phabricator via cfe-commits
barannikov88 added inline comments.



Comment at: llvm/utils/TableGen/RISCVTargetDefEmitter.cpp:52
+  for (auto &Def : Map) {
+const auto &Record = Def.second;
+if (Record->isSubClassOf("RISCVProcessorModelTUNE_PROC"))

fpetrogalli wrote:
> barannikov88 wrote:
> > Same for the loop above.
> ```
> /Users/fpetrogalli/projects/cpu-defs/upstream/llvm-project/llvm/utils/TableGen/RISCVTargetDefEmitter.cpp:38:17:
>  error: variable 'Record' with type 'const auto *' has incompatible 
> initializer of type 'const std::unique_ptr'
> const auto *Record = Def.second;
> ```
Whoops, my bad, sorry.
Never liked these 'auto's... Never know what is behind them. Looks like a raw 
pointer, but it is not.



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137517

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


  1   2   >