[clang] [webkit.RefCntblBaseVirtualDtor] Ignore a base class which has a specialized deref function for a given derived class. (PR #92501)

2024-05-16 Thread Ryosuke Niwa via cfe-commits

https://github.com/rniwa updated https://github.com/llvm/llvm-project/pull/92501

>From 87cfc8234e1294dedc103b9bcd2b7d9d31874c4a Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa 
Date: Thu, 16 May 2024 23:24:13 -0700
Subject: [PATCH 1/3] [webkit.RefCntblBaseVirtualDtor] Ignore a base class
 which has a specialized deref function for a given derived class.

When a base class B has a deref function which calls delete operator on a 
derived class D,
don't emit a warning for B even if it did not have a virtual destructor.
---
 .../WebKit/RefCntblBaseVirtualDtorChecker.cpp | 140 -
 .../ref-cntbl-base-virtual-dtor-templates.cpp | 196 +-
 2 files changed, 330 insertions(+), 6 deletions(-)

diff --git 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp
index 7f4c3a7b787e8..36ab581f1edbd 100644
--- 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp
+++ 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp
@@ -11,16 +11,128 @@
 #include "PtrTypesSemantics.h"
 #include "clang/AST/CXXInheritance.h"
 #include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/StmtVisitor.h"
 #include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
+#include "llvm/ADT/DenseSet.h"
 #include 
 
 using namespace clang;
 using namespace ento;
 
 namespace {
+
+class DerefAnalysisVisitor
+: public ConstStmtVisitor {
+  // Returns true if any of child statements return true.
+  bool VisitChildren(const Stmt *S) {
+for (const Stmt *Child : S->children()) {
+  if (Child && Visit(Child))
+return true;
+}
+return false;
+  }
+
+  bool VisitBody(const Stmt *Body) {
+if (!Body)
+  return false;
+
+auto [It, IsNew] = VisitedBody.insert(Body);
+if (!IsNew) // This body is recursive
+  return false;
+
+return Visit(Body);
+  }
+
+public:
+  DerefAnalysisVisitor(const TemplateArgumentList &ArgList,
+   const CXXRecordDecl *ClassDecl)
+: ArgList(&ArgList)
+, ClassDecl(ClassDecl)
+  { }
+
+  DerefAnalysisVisitor(const CXXRecordDecl *ClassDecl)
+: ClassDecl(ClassDecl)
+  { }
+
+  bool HasSpecializedDelete(CXXMethodDecl *Decl) {
+if (auto *Tmpl = Decl->getTemplateInstantiationPattern())
+  return VisitBody(Tmpl->getBody());
+return VisitBody(Decl->getBody());
+  }
+
+  bool VisitCallExpr(const CallExpr *CE) {
+auto *Callee = CE->getCallee();
+while (auto *Expr = dyn_cast(Callee))
+  Callee = Expr->getSubExpr();
+if (auto *DeclRef = dyn_cast(Callee)) {
+  auto *Decl = DeclRef->getDecl();
+  if (auto *VD = dyn_cast(Decl)) {
+if (auto *Init = VD->getInit()) {
+  if (auto *Lambda = dyn_cast(Init))
+return VisitBody(Lambda->getBody());
+}
+  } else if (auto *FD = dyn_cast(Decl))
+return VisitBody(FD->getBody());
+}
+return false;
+  }
+
+  bool VisitCXXMemberCallExpr(const CXXMemberCallExpr *MCE) {
+auto *Callee = MCE->getMethodDecl();
+if (!Callee)
+  return false;
+return VisitBody(Callee->getBody());
+  }
+
+  bool VisitCXXDeleteExpr(const CXXDeleteExpr *E) {
+auto *Arg = E->getArgument();
+while (Arg) {
+  if (auto *Paren = dyn_cast(Arg))
+Arg = Paren->getSubExpr();
+  else if (auto *Cast = dyn_cast(Arg)) {
+Arg = Cast->getSubExpr();
+auto CastType = Cast->getType();
+if (auto *PtrType = dyn_cast(CastType)) {
+  auto PointeeType = PtrType->getPointeeType();
+  while (auto *ET = dyn_cast(PointeeType)) {
+if (ET->isSugared())
+  PointeeType = ET->desugar();
+  }
+  if (auto *ParmType = dyn_cast(PointeeType)) {
+if (ArgList) {
+  auto ParmIndex = ParmType->getIndex();
+  auto Type = ArgList->get(ParmIndex).getAsType();
+  if (auto *RD = dyn_cast(Type)) {
+if (RD->getDecl() == ClassDecl)
+  return true;
+  }
+}
+  } else if (auto *RD = dyn_cast(PointeeType)) {
+if (RD->getDecl() == ClassDecl)
+  return true;
+  }
+}
+  } else
+break;
+}
+return false;
+  }
+
+  bool VisitStmt(const Stmt *S) { return VisitChildren(S); }
+
+  // Return false since the contents of lambda isn't necessarily executed.
+  // If it is executed, VisitCallExpr above will visit its body.
+  bool VisitLambdaExpr(const LambdaExpr *) { return false; }
+
+private:
+  const TemplateArgumentList* ArgList { nullptr };
+  const CXXRecordDecl* ClassDecl;
+  llvm::DenseSet VisitedBody;
+};
+
 class RefCntblBaseVirtualDtorChecker
 : public Checker> {
 private:
@@ -91,8 +2

[clang] [analyzer][NFC] Require explicit matching mode for CallDescriptions (PR #92454)

2024-05-16 Thread Balazs Benics via cfe-commits
=?utf-8?q?Don=C3=A1t?= Nagy 
Message-ID:
In-Reply-To: 


https://github.com/steakhal approved this pull request.


https://github.com/llvm/llvm-project/pull/92454
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [webkit.RefCntblBaseVirtualDtor] Ignore a base class which has a specialized deref function for a given derived class. (PR #92501)

2024-05-16 Thread Ryosuke Niwa via cfe-commits

https://github.com/rniwa updated https://github.com/llvm/llvm-project/pull/92501

>From 87cfc8234e1294dedc103b9bcd2b7d9d31874c4a Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa 
Date: Thu, 16 May 2024 23:24:13 -0700
Subject: [PATCH 1/2] [webkit.RefCntblBaseVirtualDtor] Ignore a base class
 which has a specialized deref function for a given derived class.

When a base class B has a deref function which calls delete operator on a 
derived class D,
don't emit a warning for B even if it did not have a virtual destructor.
---
 .../WebKit/RefCntblBaseVirtualDtorChecker.cpp | 140 -
 .../ref-cntbl-base-virtual-dtor-templates.cpp | 196 +-
 2 files changed, 330 insertions(+), 6 deletions(-)

diff --git 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp
index 7f4c3a7b787e8..36ab581f1edbd 100644
--- 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp
+++ 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp
@@ -11,16 +11,128 @@
 #include "PtrTypesSemantics.h"
 #include "clang/AST/CXXInheritance.h"
 #include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/StmtVisitor.h"
 #include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
+#include "llvm/ADT/DenseSet.h"
 #include 
 
 using namespace clang;
 using namespace ento;
 
 namespace {
+
+class DerefAnalysisVisitor
+: public ConstStmtVisitor {
+  // Returns true if any of child statements return true.
+  bool VisitChildren(const Stmt *S) {
+for (const Stmt *Child : S->children()) {
+  if (Child && Visit(Child))
+return true;
+}
+return false;
+  }
+
+  bool VisitBody(const Stmt *Body) {
+if (!Body)
+  return false;
+
+auto [It, IsNew] = VisitedBody.insert(Body);
+if (!IsNew) // This body is recursive
+  return false;
+
+return Visit(Body);
+  }
+
+public:
+  DerefAnalysisVisitor(const TemplateArgumentList &ArgList,
+   const CXXRecordDecl *ClassDecl)
+: ArgList(&ArgList)
+, ClassDecl(ClassDecl)
+  { }
+
+  DerefAnalysisVisitor(const CXXRecordDecl *ClassDecl)
+: ClassDecl(ClassDecl)
+  { }
+
+  bool HasSpecializedDelete(CXXMethodDecl *Decl) {
+if (auto *Tmpl = Decl->getTemplateInstantiationPattern())
+  return VisitBody(Tmpl->getBody());
+return VisitBody(Decl->getBody());
+  }
+
+  bool VisitCallExpr(const CallExpr *CE) {
+auto *Callee = CE->getCallee();
+while (auto *Expr = dyn_cast(Callee))
+  Callee = Expr->getSubExpr();
+if (auto *DeclRef = dyn_cast(Callee)) {
+  auto *Decl = DeclRef->getDecl();
+  if (auto *VD = dyn_cast(Decl)) {
+if (auto *Init = VD->getInit()) {
+  if (auto *Lambda = dyn_cast(Init))
+return VisitBody(Lambda->getBody());
+}
+  } else if (auto *FD = dyn_cast(Decl))
+return VisitBody(FD->getBody());
+}
+return false;
+  }
+
+  bool VisitCXXMemberCallExpr(const CXXMemberCallExpr *MCE) {
+auto *Callee = MCE->getMethodDecl();
+if (!Callee)
+  return false;
+return VisitBody(Callee->getBody());
+  }
+
+  bool VisitCXXDeleteExpr(const CXXDeleteExpr *E) {
+auto *Arg = E->getArgument();
+while (Arg) {
+  if (auto *Paren = dyn_cast(Arg))
+Arg = Paren->getSubExpr();
+  else if (auto *Cast = dyn_cast(Arg)) {
+Arg = Cast->getSubExpr();
+auto CastType = Cast->getType();
+if (auto *PtrType = dyn_cast(CastType)) {
+  auto PointeeType = PtrType->getPointeeType();
+  while (auto *ET = dyn_cast(PointeeType)) {
+if (ET->isSugared())
+  PointeeType = ET->desugar();
+  }
+  if (auto *ParmType = dyn_cast(PointeeType)) {
+if (ArgList) {
+  auto ParmIndex = ParmType->getIndex();
+  auto Type = ArgList->get(ParmIndex).getAsType();
+  if (auto *RD = dyn_cast(Type)) {
+if (RD->getDecl() == ClassDecl)
+  return true;
+  }
+}
+  } else if (auto *RD = dyn_cast(PointeeType)) {
+if (RD->getDecl() == ClassDecl)
+  return true;
+  }
+}
+  } else
+break;
+}
+return false;
+  }
+
+  bool VisitStmt(const Stmt *S) { return VisitChildren(S); }
+
+  // Return false since the contents of lambda isn't necessarily executed.
+  // If it is executed, VisitCallExpr above will visit its body.
+  bool VisitLambdaExpr(const LambdaExpr *) { return false; }
+
+private:
+  const TemplateArgumentList* ArgList { nullptr };
+  const CXXRecordDecl* ClassDecl;
+  llvm::DenseSet VisitedBody;
+};
+
 class RefCntblBaseVirtualDtorChecker
 : public Checker> {
 private:
@@ -91,8 +2

[clang] [webkit.RefCntblBaseVirtualDtor] Ignore a base class which has a specialized deref function for a given derived class. (PR #92501)

2024-05-16 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 72200fcc346bee1830d9e640e42d717a55acd74c 
87cfc8234e1294dedc103b9bcd2b7d9d31874c4a -- 
clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp 
clang/test/Analysis/Checkers/WebKit/ref-cntbl-base-virtual-dtor-templates.cpp
``





View the diff from clang-format here.


``diff
diff --git 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp
index 36ab581f1e..17e5514850 100644
--- 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp
+++ 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp
@@ -49,13 +49,9 @@ class DerefAnalysisVisitor
 public:
   DerefAnalysisVisitor(const TemplateArgumentList &ArgList,
const CXXRecordDecl *ClassDecl)
-: ArgList(&ArgList)
-, ClassDecl(ClassDecl)
-  { }
+  : ArgList(&ArgList), ClassDecl(ClassDecl) {}
 
-  DerefAnalysisVisitor(const CXXRecordDecl *ClassDecl)
-: ClassDecl(ClassDecl)
-  { }
+  DerefAnalysisVisitor(const CXXRecordDecl *ClassDecl) : ClassDecl(ClassDecl) 
{}
 
   bool HasSpecializedDelete(CXXMethodDecl *Decl) {
 if (auto *Tmpl = Decl->getTemplateInstantiationPattern())
@@ -128,8 +124,8 @@ public:
   bool VisitLambdaExpr(const LambdaExpr *) { return false; }
 
 private:
-  const TemplateArgumentList* ArgList { nullptr };
-  const CXXRecordDecl* ClassDecl;
+  const TemplateArgumentList *ArgList{nullptr};
+  const CXXRecordDecl *ClassDecl;
   llvm::DenseSet VisitedBody;
 };
 
@@ -309,11 +305,11 @@ public:
   return false;
 }
 for (auto *MethodDecl : C->methods()) {
-if (safeGetName(MethodDecl) == "deref") {
-  DerefAnalysisVisitor DerefAnalysis(DerivedClass);
-  if (DerefAnalysis.HasSpecializedDelete(MethodDecl))
-return true;
-}
+  if (safeGetName(MethodDecl) == "deref") {
+DerefAnalysisVisitor DerefAnalysis(DerivedClass);
+if (DerefAnalysis.HasSpecializedDelete(MethodDecl))
+  return true;
+  }
 }
 return false;
   }

``




https://github.com/llvm/llvm-project/pull/92501
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [webkit.RefCntblBaseVirtualDtor] Ignore a base class which has a specialized deref function for a given derived class. (PR #92501)

2024-05-16 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Ryosuke Niwa (rniwa)


Changes

When a base class B has a deref function which calls delete operator on a 
derived class D, don't emit a warning for B even if it did not have a virtual 
destructor.

---
Full diff: https://github.com/llvm/llvm-project/pull/92501.diff


2 Files Affected:

- (modified) 
clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp 
(+138-2) 
- (modified) 
clang/test/Analysis/Checkers/WebKit/ref-cntbl-base-virtual-dtor-templates.cpp 
(+192-4) 


``diff
diff --git 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp
index 7f4c3a7b787e8..36ab581f1edbd 100644
--- 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp
+++ 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp
@@ -11,16 +11,128 @@
 #include "PtrTypesSemantics.h"
 #include "clang/AST/CXXInheritance.h"
 #include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/StmtVisitor.h"
 #include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
+#include "llvm/ADT/DenseSet.h"
 #include 
 
 using namespace clang;
 using namespace ento;
 
 namespace {
+
+class DerefAnalysisVisitor
+: public ConstStmtVisitor {
+  // Returns true if any of child statements return true.
+  bool VisitChildren(const Stmt *S) {
+for (const Stmt *Child : S->children()) {
+  if (Child && Visit(Child))
+return true;
+}
+return false;
+  }
+
+  bool VisitBody(const Stmt *Body) {
+if (!Body)
+  return false;
+
+auto [It, IsNew] = VisitedBody.insert(Body);
+if (!IsNew) // This body is recursive
+  return false;
+
+return Visit(Body);
+  }
+
+public:
+  DerefAnalysisVisitor(const TemplateArgumentList &ArgList,
+   const CXXRecordDecl *ClassDecl)
+: ArgList(&ArgList)
+, ClassDecl(ClassDecl)
+  { }
+
+  DerefAnalysisVisitor(const CXXRecordDecl *ClassDecl)
+: ClassDecl(ClassDecl)
+  { }
+
+  bool HasSpecializedDelete(CXXMethodDecl *Decl) {
+if (auto *Tmpl = Decl->getTemplateInstantiationPattern())
+  return VisitBody(Tmpl->getBody());
+return VisitBody(Decl->getBody());
+  }
+
+  bool VisitCallExpr(const CallExpr *CE) {
+auto *Callee = CE->getCallee();
+while (auto *Expr = dyn_cast(Callee))
+  Callee = Expr->getSubExpr();
+if (auto *DeclRef = dyn_cast(Callee)) {
+  auto *Decl = DeclRef->getDecl();
+  if (auto *VD = dyn_cast(Decl)) {
+if (auto *Init = VD->getInit()) {
+  if (auto *Lambda = dyn_cast(Init))
+return VisitBody(Lambda->getBody());
+}
+  } else if (auto *FD = dyn_cast(Decl))
+return VisitBody(FD->getBody());
+}
+return false;
+  }
+
+  bool VisitCXXMemberCallExpr(const CXXMemberCallExpr *MCE) {
+auto *Callee = MCE->getMethodDecl();
+if (!Callee)
+  return false;
+return VisitBody(Callee->getBody());
+  }
+
+  bool VisitCXXDeleteExpr(const CXXDeleteExpr *E) {
+auto *Arg = E->getArgument();
+while (Arg) {
+  if (auto *Paren = dyn_cast(Arg))
+Arg = Paren->getSubExpr();
+  else if (auto *Cast = dyn_cast(Arg)) {
+Arg = Cast->getSubExpr();
+auto CastType = Cast->getType();
+if (auto *PtrType = dyn_cast(CastType)) {
+  auto PointeeType = PtrType->getPointeeType();
+  while (auto *ET = dyn_cast(PointeeType)) {
+if (ET->isSugared())
+  PointeeType = ET->desugar();
+  }
+  if (auto *ParmType = dyn_cast(PointeeType)) {
+if (ArgList) {
+  auto ParmIndex = ParmType->getIndex();
+  auto Type = ArgList->get(ParmIndex).getAsType();
+  if (auto *RD = dyn_cast(Type)) {
+if (RD->getDecl() == ClassDecl)
+  return true;
+  }
+}
+  } else if (auto *RD = dyn_cast(PointeeType)) {
+if (RD->getDecl() == ClassDecl)
+  return true;
+  }
+}
+  } else
+break;
+}
+return false;
+  }
+
+  bool VisitStmt(const Stmt *S) { return VisitChildren(S); }
+
+  // Return false since the contents of lambda isn't necessarily executed.
+  // If it is executed, VisitCallExpr above will visit its body.
+  bool VisitLambdaExpr(const LambdaExpr *) { return false; }
+
+private:
+  const TemplateArgumentList* ArgList { nullptr };
+  const CXXRecordDecl* ClassDecl;
+  llvm::DenseSet VisitedBody;
+};
+
 class RefCntblBaseVirtualDtorChecker
 : public Checker> {
 private:
@@ -91,8 +203,6 @@ class RefCntblBaseVirtualDtorChecker
   const CXXRecordDecl *C = T->getAsCXXRecordDecl();
   if (!C)
 return false;

[clang] [webkit.RefCntblBaseVirtualDtor] Ignore a base class which has a specialized deref function for a given derived class. (PR #92501)

2024-05-16 Thread Ryosuke Niwa via cfe-commits

https://github.com/rniwa created https://github.com/llvm/llvm-project/pull/92501

When a base class B has a deref function which calls delete operator on a 
derived class D, don't emit a warning for B even if it did not have a virtual 
destructor.

>From 87cfc8234e1294dedc103b9bcd2b7d9d31874c4a Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa 
Date: Thu, 16 May 2024 23:24:13 -0700
Subject: [PATCH] [webkit.RefCntblBaseVirtualDtor] Ignore a base class which
 has a specialized deref function for a given derived class.

When a base class B has a deref function which calls delete operator on a 
derived class D,
don't emit a warning for B even if it did not have a virtual destructor.
---
 .../WebKit/RefCntblBaseVirtualDtorChecker.cpp | 140 -
 .../ref-cntbl-base-virtual-dtor-templates.cpp | 196 +-
 2 files changed, 330 insertions(+), 6 deletions(-)

diff --git 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp
index 7f4c3a7b787e8..36ab581f1edbd 100644
--- 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp
+++ 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp
@@ -11,16 +11,128 @@
 #include "PtrTypesSemantics.h"
 #include "clang/AST/CXXInheritance.h"
 #include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/StmtVisitor.h"
 #include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
+#include "llvm/ADT/DenseSet.h"
 #include 
 
 using namespace clang;
 using namespace ento;
 
 namespace {
+
+class DerefAnalysisVisitor
+: public ConstStmtVisitor {
+  // Returns true if any of child statements return true.
+  bool VisitChildren(const Stmt *S) {
+for (const Stmt *Child : S->children()) {
+  if (Child && Visit(Child))
+return true;
+}
+return false;
+  }
+
+  bool VisitBody(const Stmt *Body) {
+if (!Body)
+  return false;
+
+auto [It, IsNew] = VisitedBody.insert(Body);
+if (!IsNew) // This body is recursive
+  return false;
+
+return Visit(Body);
+  }
+
+public:
+  DerefAnalysisVisitor(const TemplateArgumentList &ArgList,
+   const CXXRecordDecl *ClassDecl)
+: ArgList(&ArgList)
+, ClassDecl(ClassDecl)
+  { }
+
+  DerefAnalysisVisitor(const CXXRecordDecl *ClassDecl)
+: ClassDecl(ClassDecl)
+  { }
+
+  bool HasSpecializedDelete(CXXMethodDecl *Decl) {
+if (auto *Tmpl = Decl->getTemplateInstantiationPattern())
+  return VisitBody(Tmpl->getBody());
+return VisitBody(Decl->getBody());
+  }
+
+  bool VisitCallExpr(const CallExpr *CE) {
+auto *Callee = CE->getCallee();
+while (auto *Expr = dyn_cast(Callee))
+  Callee = Expr->getSubExpr();
+if (auto *DeclRef = dyn_cast(Callee)) {
+  auto *Decl = DeclRef->getDecl();
+  if (auto *VD = dyn_cast(Decl)) {
+if (auto *Init = VD->getInit()) {
+  if (auto *Lambda = dyn_cast(Init))
+return VisitBody(Lambda->getBody());
+}
+  } else if (auto *FD = dyn_cast(Decl))
+return VisitBody(FD->getBody());
+}
+return false;
+  }
+
+  bool VisitCXXMemberCallExpr(const CXXMemberCallExpr *MCE) {
+auto *Callee = MCE->getMethodDecl();
+if (!Callee)
+  return false;
+return VisitBody(Callee->getBody());
+  }
+
+  bool VisitCXXDeleteExpr(const CXXDeleteExpr *E) {
+auto *Arg = E->getArgument();
+while (Arg) {
+  if (auto *Paren = dyn_cast(Arg))
+Arg = Paren->getSubExpr();
+  else if (auto *Cast = dyn_cast(Arg)) {
+Arg = Cast->getSubExpr();
+auto CastType = Cast->getType();
+if (auto *PtrType = dyn_cast(CastType)) {
+  auto PointeeType = PtrType->getPointeeType();
+  while (auto *ET = dyn_cast(PointeeType)) {
+if (ET->isSugared())
+  PointeeType = ET->desugar();
+  }
+  if (auto *ParmType = dyn_cast(PointeeType)) {
+if (ArgList) {
+  auto ParmIndex = ParmType->getIndex();
+  auto Type = ArgList->get(ParmIndex).getAsType();
+  if (auto *RD = dyn_cast(Type)) {
+if (RD->getDecl() == ClassDecl)
+  return true;
+  }
+}
+  } else if (auto *RD = dyn_cast(PointeeType)) {
+if (RD->getDecl() == ClassDecl)
+  return true;
+  }
+}
+  } else
+break;
+}
+return false;
+  }
+
+  bool VisitStmt(const Stmt *S) { return VisitChildren(S); }
+
+  // Return false since the contents of lambda isn't necessarily executed.
+  // If it is executed, VisitCallExpr above will visit its body.
+  bool VisitLambdaExpr(const LambdaExpr *) { return false; }
+
+private:
+  const TemplateArgumentList* ArgList { null

[clang] [clang][NFC] Remove const-qualification from `FunctionTemplateSpecializationInfo::TemplateArguments` (PR #92500)

2024-05-16 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Vlad Serebrennikov (Endilll)


Changes

This patch remove const-qualification from pointee type of 
`FunctionTemplateSpecializationInfo::TemplateArguments`, because it's 
(eventually) used to initialize `MultiLevelTemplateArgumentList`, which can 
actually mutate the arguments via
https://github.com/llvm/llvm-project/blob/f42f57b52dd279e6ae19270d063aeb8d59e3f11c/clang/include/clang/Sema/Template.h#L197-L204
Mutation seems to be required to correctly handle packs:
https://github.com/llvm/llvm-project/blob/9144553207052a868efc5a8ce61a0afbb0eaf236/clang/lib/Sema/SemaTemplateInstantiate.cpp#L1440-L1469

---
Full diff: https://github.com/llvm/llvm-project/pull/92500.diff


5 Files Affected:

- (modified) clang/include/clang/AST/Decl.h (+12-13) 
- (modified) clang/include/clang/AST/DeclTemplate.h (+3-4) 
- (modified) clang/lib/AST/Decl.cpp (+6-8) 
- (modified) clang/lib/AST/DeclTemplate.cpp (+1-1) 
- (modified) clang/lib/Sema/SemaTemplate.cpp (+1-1) 


``diff
diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index de8b923645f8d..5e485ccb85a13 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -2096,13 +2096,12 @@ class FunctionDecl : public DeclaratorDecl,
   ///
   /// \param PointOfInstantiation point at which the function template
   /// specialization was first instantiated.
-  void setFunctionTemplateSpecialization(ASTContext &C,
- FunctionTemplateDecl *Template,
-   const TemplateArgumentList 
*TemplateArgs,
- void *InsertPos,
- TemplateSpecializationKind TSK,
-  const TemplateArgumentListInfo 
*TemplateArgsAsWritten,
- SourceLocation PointOfInstantiation);
+  void setFunctionTemplateSpecialization(
+  ASTContext &C, FunctionTemplateDecl *Template,
+  TemplateArgumentList *TemplateArgs, void *InsertPos,
+  TemplateSpecializationKind TSK,
+  const TemplateArgumentListInfo *TemplateArgsAsWritten,
+  SourceLocation PointOfInstantiation);
 
   /// Specify that this record is an instantiation of the
   /// member function FD.
@@ -2981,12 +2980,12 @@ class FunctionDecl : public DeclaratorDecl,
   ///
   /// \param PointOfInstantiation point at which the function template
   /// specialization was first instantiated.
-  void setFunctionTemplateSpecialization(FunctionTemplateDecl *Template,
-const TemplateArgumentList *TemplateArgs,
-void *InsertPos,
-TemplateSpecializationKind TSK = TSK_ImplicitInstantiation,
-const TemplateArgumentListInfo *TemplateArgsAsWritten = 
nullptr,
-SourceLocation PointOfInstantiation = SourceLocation()) {
+  void setFunctionTemplateSpecialization(
+  FunctionTemplateDecl *Template, TemplateArgumentList *TemplateArgs,
+  void *InsertPos,
+  TemplateSpecializationKind TSK = TSK_ImplicitInstantiation,
+  TemplateArgumentListInfo *TemplateArgsAsWritten = nullptr,
+  SourceLocation PointOfInstantiation = SourceLocation()) {
 setFunctionTemplateSpecialization(getASTContext(), Template, TemplateArgs,
   InsertPos, TSK, TemplateArgsAsWritten,
   PointOfInstantiation);
diff --git a/clang/include/clang/AST/DeclTemplate.h 
b/clang/include/clang/AST/DeclTemplate.h
index 268aeacf2f20f..f3d6a321ecf10 100644
--- a/clang/include/clang/AST/DeclTemplate.h
+++ b/clang/include/clang/AST/DeclTemplate.h
@@ -478,7 +478,7 @@ class FunctionTemplateSpecializationInfo final
 public:
   /// The template arguments used to produce the function template
   /// specialization from the function template.
-  const TemplateArgumentList *TemplateArguments;
+  TemplateArgumentList *TemplateArguments;
 
   /// The template arguments as written in the sources, if provided.
   /// FIXME: Normally null; tail-allocate this.
@@ -491,7 +491,7 @@ class FunctionTemplateSpecializationInfo final
 private:
   FunctionTemplateSpecializationInfo(
   FunctionDecl *FD, FunctionTemplateDecl *Template,
-  TemplateSpecializationKind TSK, const TemplateArgumentList *TemplateArgs,
+  TemplateSpecializationKind TSK, TemplateArgumentList *TemplateArgs,
   const ASTTemplateArgumentListInfo *TemplateArgsAsWritten,
   SourceLocation POI, MemberSpecializationInfo *MSInfo)
   : Function(FD, MSInfo ? true : false), Template(Template, TSK - 1),
@@ -511,8 +511,7 @@ class FunctionTemplateSpecializationInfo final
 
   static FunctionTemplateSpecializationInfo *
   Create(ASTContext &C, FunctionDecl *FD, FunctionTemplateDecl *Template,
- TemplateSpecializationKind TSK,
- const TemplateArgumentList *TemplateArgs,
+ TemplateSpecializationKind TSK, TemplateArgumentList *TemplateArg

[clang] [clang][NFC] Remove const-qualification from `FunctionTemplateSpecializationInfo::TemplateArguments` (PR #92500)

2024-05-16 Thread Vlad Serebrennikov via cfe-commits

https://github.com/Endilll created 
https://github.com/llvm/llvm-project/pull/92500

This patch remove const-qualification from pointee type of 
`FunctionTemplateSpecializationInfo::TemplateArguments`, because it's 
(eventually) used to initialize `MultiLevelTemplateArgumentList`, which can 
actually mutate the arguments via
https://github.com/llvm/llvm-project/blob/f42f57b52dd279e6ae19270d063aeb8d59e3f11c/clang/include/clang/Sema/Template.h#L197-L204
Mutation seems to be required to correctly handle packs:
https://github.com/llvm/llvm-project/blob/9144553207052a868efc5a8ce61a0afbb0eaf236/clang/lib/Sema/SemaTemplateInstantiate.cpp#L1440-L1469

>From a8a6e0dae0ac0903f6cc759ff2680320ab96d2dc Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Fri, 17 May 2024 09:09:29 +0300
Subject: [PATCH] [clang][NFC] Remove const-qualification from
 `FunctionTemplateSpecializationInfo::TemplateArguments`

---
 clang/include/clang/AST/Decl.h | 25 -
 clang/include/clang/AST/DeclTemplate.h |  7 +++
 clang/lib/AST/Decl.cpp | 14 ++
 clang/lib/AST/DeclTemplate.cpp |  2 +-
 clang/lib/Sema/SemaTemplate.cpp|  2 +-
 5 files changed, 23 insertions(+), 27 deletions(-)

diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index de8b923645f8d..5e485ccb85a13 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -2096,13 +2096,12 @@ class FunctionDecl : public DeclaratorDecl,
   ///
   /// \param PointOfInstantiation point at which the function template
   /// specialization was first instantiated.
-  void setFunctionTemplateSpecialization(ASTContext &C,
- FunctionTemplateDecl *Template,
-   const TemplateArgumentList 
*TemplateArgs,
- void *InsertPos,
- TemplateSpecializationKind TSK,
-  const TemplateArgumentListInfo 
*TemplateArgsAsWritten,
- SourceLocation PointOfInstantiation);
+  void setFunctionTemplateSpecialization(
+  ASTContext &C, FunctionTemplateDecl *Template,
+  TemplateArgumentList *TemplateArgs, void *InsertPos,
+  TemplateSpecializationKind TSK,
+  const TemplateArgumentListInfo *TemplateArgsAsWritten,
+  SourceLocation PointOfInstantiation);
 
   /// Specify that this record is an instantiation of the
   /// member function FD.
@@ -2981,12 +2980,12 @@ class FunctionDecl : public DeclaratorDecl,
   ///
   /// \param PointOfInstantiation point at which the function template
   /// specialization was first instantiated.
-  void setFunctionTemplateSpecialization(FunctionTemplateDecl *Template,
-const TemplateArgumentList *TemplateArgs,
-void *InsertPos,
-TemplateSpecializationKind TSK = TSK_ImplicitInstantiation,
-const TemplateArgumentListInfo *TemplateArgsAsWritten = 
nullptr,
-SourceLocation PointOfInstantiation = SourceLocation()) {
+  void setFunctionTemplateSpecialization(
+  FunctionTemplateDecl *Template, TemplateArgumentList *TemplateArgs,
+  void *InsertPos,
+  TemplateSpecializationKind TSK = TSK_ImplicitInstantiation,
+  TemplateArgumentListInfo *TemplateArgsAsWritten = nullptr,
+  SourceLocation PointOfInstantiation = SourceLocation()) {
 setFunctionTemplateSpecialization(getASTContext(), Template, TemplateArgs,
   InsertPos, TSK, TemplateArgsAsWritten,
   PointOfInstantiation);
diff --git a/clang/include/clang/AST/DeclTemplate.h 
b/clang/include/clang/AST/DeclTemplate.h
index 268aeacf2f20f..f3d6a321ecf10 100644
--- a/clang/include/clang/AST/DeclTemplate.h
+++ b/clang/include/clang/AST/DeclTemplate.h
@@ -478,7 +478,7 @@ class FunctionTemplateSpecializationInfo final
 public:
   /// The template arguments used to produce the function template
   /// specialization from the function template.
-  const TemplateArgumentList *TemplateArguments;
+  TemplateArgumentList *TemplateArguments;
 
   /// The template arguments as written in the sources, if provided.
   /// FIXME: Normally null; tail-allocate this.
@@ -491,7 +491,7 @@ class FunctionTemplateSpecializationInfo final
 private:
   FunctionTemplateSpecializationInfo(
   FunctionDecl *FD, FunctionTemplateDecl *Template,
-  TemplateSpecializationKind TSK, const TemplateArgumentList *TemplateArgs,
+  TemplateSpecializationKind TSK, TemplateArgumentList *TemplateArgs,
   const ASTTemplateArgumentListInfo *TemplateArgsAsWritten,
   SourceLocation POI, MemberSpecializationInfo *MSInfo)
   : Function(FD, MSInfo ? true : false), Template(Template, TSK - 1),
@@ -511,8 +511,7 @@ class FunctionTemplateSpecializationInfo final
 
   static FunctionTemplateSpecializationInfo *
   Create(ASTContext &C, Funct

[clang] [clang-tools-extra] [compiler-rt] [lldb] [llvm] [mlir] [openmp] [polly] fix(python): fix comparison to None (PR #91857)

2024-05-16 Thread Maksim Levental via cfe-commits

https://github.com/makslevental approved this pull request.

There you go - diligently reviewed using GitHub 's fantastic UI.

![Screenshot_20240517_011154_com android 
chrome](https://github.com/llvm/llvm-project/assets/5657668/ece87aff-4c44-4f07-8176-1adeaa4ff32e)


https://github.com/llvm/llvm-project/pull/91857
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [compiler-rt] [lldb] [llvm] [mlir] [openmp] [polly] fix(python): fix comparison to None (PR #91857)

2024-05-16 Thread Maksim Levental via cfe-commits

makslevental wrote:

It's a `sed s/== None/is None/g` - what is there to review? 10 separate PRs for 
the same exact `sed` costs more in commit noise (and effort on the part of 
@e-kwsm) than one solid, patient, review here.

https://github.com/llvm/llvm-project/pull/91857
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] clang: add unnamed_addr function attribute (PR #92499)

2024-05-16 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: YAMAMOTO Takashi (yamt)


Changes

It simply applies the LLVM attribute with the same name to the function.

Sometimes, a programmer knows that function pointer uniqueness doesn't really 
matter for some of their functions. In that case, this attribute opens a 
possibility of certain optimizations like mergefunc with aliases. It's 
especially useful for code generators.

---
Full diff: https://github.com/llvm/llvm-project/pull/92499.diff


2 Files Affected:

- (modified) clang/include/clang/Basic/Attr.td (+7) 
- (modified) clang/lib/CodeGen/CodeGenModule.cpp (+4) 


``diff
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 52552ba488560..3ee7d43d339f1 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1944,6 +1944,13 @@ def ReturnsTwice : InheritableAttr {
   let SimpleHandler = 1;
 }
 
+def UnnamedAddr : InheritableAttr {
+  let Spellings = [Clang<"unnamed_addr">];
+  let Subjects = SubjectList<[Function]>;
+  let Documentation = [Undocumented];
+  let SimpleHandler = 1;
+}
+
 def DisableTailCalls : InheritableAttr {
   let Spellings = [Clang<"disable_tail_calls">];
   let Subjects = SubjectList<[Function, ObjCMethod]>;
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 489c08a4d4819..ac9f082a1049b 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -2506,6 +2506,10 @@ void 
CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D,
   B.addAttribute(llvm::Attribute::MinSize);
   }
 
+  if (D->hasAttr()) {
+F->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
+  }
+
   F->addFnAttrs(B);
 
   unsigned alignment = D->getMaxAlignment() / Context.getCharWidth();

``




https://github.com/llvm/llvm-project/pull/92499
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] clang: add unnamed_addr function attribute (PR #92499)

2024-05-16 Thread YAMAMOTO Takashi via cfe-commits

https://github.com/yamt created https://github.com/llvm/llvm-project/pull/92499

It simply applies the LLVM attribute with the same name to the function.

Sometimes, a programmer knows that function pointer uniqueness doesn't really 
matter for some of their functions. In that case, this attribute opens a 
possibility of certain optimizations like mergefunc with aliases. It's 
especially useful for code generators.

>From 1c1bedf655de10d2e4f0122975db1950f2203a96 Mon Sep 17 00:00:00 2001
From: YAMAMOTO Takashi 
Date: Fri, 17 May 2024 14:47:06 +0900
Subject: [PATCH] clang: add unnamed_addr function attribute

It simply applies the LLVM attribute with the same name to the function.

Sometimes, a programmer knows that function pointer uniqueness doesn't
really matter for some of their functions. In that case, this attribute
opens a possibility of certain optimizations like mergefunc with aliases.
It's especially useful for code generators.
---
 clang/include/clang/Basic/Attr.td   | 7 +++
 clang/lib/CodeGen/CodeGenModule.cpp | 4 
 2 files changed, 11 insertions(+)

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 52552ba488560..3ee7d43d339f1 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1944,6 +1944,13 @@ def ReturnsTwice : InheritableAttr {
   let SimpleHandler = 1;
 }
 
+def UnnamedAddr : InheritableAttr {
+  let Spellings = [Clang<"unnamed_addr">];
+  let Subjects = SubjectList<[Function]>;
+  let Documentation = [Undocumented];
+  let SimpleHandler = 1;
+}
+
 def DisableTailCalls : InheritableAttr {
   let Spellings = [Clang<"disable_tail_calls">];
   let Subjects = SubjectList<[Function, ObjCMethod]>;
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 489c08a4d4819..ac9f082a1049b 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -2506,6 +2506,10 @@ void 
CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D,
   B.addAttribute(llvm::Attribute::MinSize);
   }
 
+  if (D->hasAttr()) {
+F->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
+  }
+
   F->addFnAttrs(B);
 
   unsigned alignment = D->getMaxAlignment() / Context.getCharWidth();

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


[clang] f71749c - [clang] Drop explicit conversions of string literals to StringRef (NFC)

2024-05-16 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2024-05-16T22:32:06-07:00
New Revision: f71749c5ef8667e3fc23820e8e94864653ea9ac9

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

LOG: [clang] Drop explicit conversions of string literals to StringRef (NFC)

We routinely rely on implicit conversions of string literals to
StringRef so that we can use operator==(StringRef, StringRef).

The LHS here are all known to be of StringRef.

Added: 


Modified: 
clang/lib/Analysis/ThreadSafetyCommon.cpp
clang/lib/Sema/SemaDeclAttr.cpp
clang/lib/Serialization/ASTWriter.cpp

Removed: 




diff  --git a/clang/lib/Analysis/ThreadSafetyCommon.cpp 
b/clang/lib/Analysis/ThreadSafetyCommon.cpp
index 33f1f466df244..a3b378c42df33 100644
--- a/clang/lib/Analysis/ThreadSafetyCommon.cpp
+++ b/clang/lib/Analysis/ThreadSafetyCommon.cpp
@@ -177,7 +177,7 @@ CapabilityExpr SExprBuilder::translateAttrExpr(const Expr 
*AttrExp,
 return CapabilityExpr();
 
   if (const auto* SLit = dyn_cast(AttrExp)) {
-if (SLit->getString() == StringRef("*"))
+if (SLit->getString() == "*")
   // The "*" expr is a universal lock, which essentially turns off
   // checks until it is removed from the lockset.
   return CapabilityExpr(new (Arena) til::Wildcard(), StringRef("wildcard"),

diff  --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 3760a4c917ad7..30776ff537fb5 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -640,7 +640,7 @@ static void checkAttrArgsAreCapabilityObjs(Sema &S, Decl *D,
 
 if (const auto *StrLit = dyn_cast(ArgExp)) {
   if (StrLit->getLength() == 0 ||
-  (StrLit->isOrdinary() && StrLit->getString() == StringRef("*"))) {
+  (StrLit->isOrdinary() && StrLit->getString() == "*")) {
 // Pass empty strings to the analyzer without warnings.
 // Treat "*" as the universal lock.
 Args.push_back(ArgExp);

diff  --git a/clang/lib/Serialization/ASTWriter.cpp 
b/clang/lib/Serialization/ASTWriter.cpp
index 129bc337c8924..dd5d65b2eb20e 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -1460,7 +1460,7 @@ void ASTWriter::WriteControlBlock(Preprocessor &PP, 
ASTContext &Context,
 (!PP.getHeaderSearchInfo()
   .getHeaderSearchOpts()
   .ModuleMapFileHomeIsCwd ||
- WritingModule->Directory->getName() != StringRef("."))) {
+ WritingModule->Directory->getName() != ".")) {
   // Module directory.
   auto Abbrev = std::make_shared();
   Abbrev->Add(BitCodeAbbrevOp(MODULE_DIRECTORY));



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


[clang] [CodeGen] Support arrays with initializers of 64-bit size (PR #92473)

2024-05-16 Thread Fangrui Song via cfe-commits


@@ -949,11 +949,11 @@ tryEmitGlobalCompoundLiteral(ConstantEmitter &emitter,
 
 static llvm::Constant *
 EmitArrayConstant(CodeGenModule &CGM, llvm::ArrayType *DesiredType,
-  llvm::Type *CommonElementType, unsigned ArrayBound,
+  llvm::Type *CommonElementType, uint64_t ArrayBound,
   SmallVectorImpl &Elements,
   llvm::Constant *Filler) {
   // Figure out how long the initial prefix of non-zero elements is.
-  unsigned NonzeroLength = ArrayBound;
+  uint64_t NonzeroLength = ArrayBound;
   if (Elements.size() < NonzeroLength && Filler->isNullValue())
 NonzeroLength = Elements.size();
   if (NonzeroLength == Elements.size()) {

MaskRay wrote:

Thanks for catching this. Fixed and added a test.

https://github.com/llvm/llvm-project/pull/92473
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [CodeGen] Support arrays with initializers of 64-bit size (PR #92473)

2024-05-16 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay updated 
https://github.com/llvm/llvm-project/pull/92473

>From fec942ed085d2a4004a6cefcb7fdf20a4b062ca3 Mon Sep 17 00:00:00 2001
From: Fangrui Song 
Date: Thu, 16 May 2024 16:24:01 -0700
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
 =?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.5-bogner
---
 clang/lib/CodeGen/CGExprConstant.cpp | 12 ++--
 clang/lib/Sema/SemaInit.cpp  |  4 ++--
 clang/test/CodeGen/array-init.c  |  7 +++
 3 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/clang/lib/CodeGen/CGExprConstant.cpp 
b/clang/lib/CodeGen/CGExprConstant.cpp
index 94962091116af..ce57279a6eb65 100644
--- a/clang/lib/CodeGen/CGExprConstant.cpp
+++ b/clang/lib/CodeGen/CGExprConstant.cpp
@@ -393,7 +393,7 @@ bool ConstantAggregateBuilder::split(size_t Index, 
CharUnits Hint) {
 
 static llvm::Constant *
 EmitArrayConstant(CodeGenModule &CGM, llvm::ArrayType *DesiredType,
-  llvm::Type *CommonElementType, unsigned ArrayBound,
+  llvm::Type *CommonElementType, uint64_t ArrayBound,
   SmallVectorImpl &Elements,
   llvm::Constant *Filler);
 
@@ -949,11 +949,11 @@ tryEmitGlobalCompoundLiteral(ConstantEmitter &emitter,
 
 static llvm::Constant *
 EmitArrayConstant(CodeGenModule &CGM, llvm::ArrayType *DesiredType,
-  llvm::Type *CommonElementType, unsigned ArrayBound,
+  llvm::Type *CommonElementType, uint64_t ArrayBound,
   SmallVectorImpl &Elements,
   llvm::Constant *Filler) {
   // Figure out how long the initial prefix of non-zero elements is.
-  unsigned NonzeroLength = ArrayBound;
+  uint64_t NonzeroLength = ArrayBound;
   if (Elements.size() < NonzeroLength && Filler->isNullValue())
 NonzeroLength = Elements.size();
   if (NonzeroLength == Elements.size()) {
@@ -1252,12 +1252,12 @@ class ConstExprEmitter
   llvm::Constant *EmitArrayInitialization(const InitListExpr *ILE, QualType T) 
{
 auto *CAT = CGM.getContext().getAsConstantArrayType(ILE->getType());
 assert(CAT && "can't emit array init for non-constant-bound array");
-unsigned NumInitElements = ILE->getNumInits();
-unsigned NumElements = CAT->getZExtSize();
+const uint64_t NumElements = CAT->getZExtSize();
 
 // Initialising an array requires us to automatically
 // initialise any elements that have not been initialised explicitly
-unsigned NumInitableElts = std::min(NumInitElements, NumElements);
+uint64_t NumInitableElts =
+std::min(ILE->getNumInits(), NumElements);
 
 QualType EltType = CAT->getElementType();
 
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 2177972f3af2c..353e911c5cc33 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -876,7 +876,7 @@ InitListChecker::FillInEmptyInitializations(const 
InitializedEntity &Entity,
 
   InitializedEntity ElementEntity = Entity;
   unsigned NumInits = ILE->getNumInits();
-  unsigned NumElements = NumInits;
+  uint64_t NumElements = NumInits;
   if (const ArrayType *AType = SemaRef.Context.getAsArrayType(ILE->getType())) 
{
 ElementType = AType->getElementType();
 if (const auto *CAType = dyn_cast(AType))
@@ -896,7 +896,7 @@ InitListChecker::FillInEmptyInitializations(const 
InitializedEntity &Entity,
 ElementType = ILE->getType();
 
   bool SkipEmptyInitChecks = false;
-  for (unsigned Init = 0; Init != NumElements; ++Init) {
+  for (uint64_t Init = 0; Init != NumElements; ++Init) {
 if (hadError)
   return;
 
diff --git a/clang/test/CodeGen/array-init.c b/clang/test/CodeGen/array-init.c
index 62e87edc29741..9075df68c7358 100644
--- a/clang/test/CodeGen/array-init.c
+++ b/clang/test/CodeGen/array-init.c
@@ -13,3 +13,10 @@ void testConstArrayInits(void)
   const int a2[5] = {0,0,0};
   const int a3[5] = {0};
 }
+
+/// https://github.com/llvm/llvm-project/issues/57353
+// CHECK: @big_char ={{.*}} global <{ i8, [4294967295 x i8] }> <{ i8 1, 
[4294967295 x i8] zeroinitializer }>
+char big_char[4294967296] = {1};
+
+// CHECK: @big_int ={{.*}} global <{ i32, [2147483647 x i32] }> <{ i32 1, 
[2147483647 x i32] zeroinitializer }>
+int big_int[0x2 >> 2] = {1};

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


[clang] HLSL availability diagnostics design doc (PR #92207)

2024-05-16 Thread Helena Kotas via cfe-commits

https://github.com/hekota updated 
https://github.com/llvm/llvm-project/pull/92207

>From 3df0ba0fd2171a0115427bc6ba5e3f8e84831747 Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Tue, 14 May 2024 19:06:59 -0700
Subject: [PATCH 1/7] HLSL Availability Diagnostics Design Document - initial
 commit

---
 clang/docs/HLSL/AvailabilityDiagnostics.rst | 50 +
 clang/docs/HLSL/HLSLDocs.rst|  1 +
 2 files changed, 51 insertions(+)
 create mode 100644 clang/docs/HLSL/AvailabilityDiagnostics.rst

diff --git a/clang/docs/HLSL/AvailabilityDiagnostics.rst 
b/clang/docs/HLSL/AvailabilityDiagnostics.rst
new file mode 100644
index 0..218047495e6b9
--- /dev/null
+++ b/clang/docs/HLSL/AvailabilityDiagnostics.rst
@@ -0,0 +1,50 @@
+=
+HLSL Availability Diagnostics
+=
+
+.. contents::
+   :local:
+
+Introduction
+
+
+HLSL availability diagnostics emits errors or warning when unavailable shader 
APIs are used. Unavailable shader APIs are APIs that are exposed in HLSL code 
but are not available in the target shader stage or shader model version.
+
+There are three modes of HLSL availability diagnostic:
+1. **Default mode** - compiler emits an error when an unavailable shader API 
is found in a code that is reachable from the shader entry point function or 
from an exported library function (when compiling a shader library)
+2. **Relaxed mode** - same as default mode except the compiler emits a 
warning. This mode is enabled by ``-Wno-error=hlsl-availability``.
+3. **Strict mode** - compiler emits an error when when an unavailable API is 
found in parsed code regardless of whether it can be reached from the shader 
entry point or exported functions, or not. This mode is enabled by 
``-fhlsl-strict-diagnostics``.
+
+Implementation Details
+==
+
+Environment Parameter
+-
+
+In order to encode API availability based on the shader model version and 
shader model stage a new ``environment`` parameter was added to the existing 
Clang ``availability`` attribute. 
+
+The values allowed for this parameter are a subset of values allowed as the 
``llvm::Triple`` environment component. If the environment parameters is 
present, the declared availability attribute applies only to targets with the 
same platform and environment.
+
+Default and Relaxed Diagnostic Modes
+
+
+This mode is implemeted in ``DiagnoseHLSLAvailability`` class in 
``SemaHLSL.cpp`` and it is invoked after the whole translation unit is parsed 
(from ``Sema::ActOnEndOfTranslationUnit``). The implementation iterates over 
all shader entry points and exported library functions in the translation unit 
and performs an AST traversal of each function body.
+
+When a reference to another function is found and it has a body, the AST of 
the referenced function is also scanned. This chain of AST traversals will 
reach all of the code that is reachable from the initial shader entry point or 
exported library function.
+
+All shader APIs have an availability attribute that specifies the shader model 
version (and environment, if applicable) when this API was first 
introduced.When a reference to a function without a definition is found and it 
has an availability attribute, the version of the attribute is checked against 
the target shader model version and shader stage (if shader stage context is 
known), and an appropriate diagnostic is generated as needed.
+
+All shader entry functions have ``HLSLShaderAttr`` attribute that specifies 
what type of shader this function represents. However, for exported library 
functions the target shader stage is unknown, so in this case the HLSL API 
availability will be only checked against the shader model version.
+
+A list of functions that were already scanned is kept in order to avoid 
duplicate scans and diagnostics (see 
``DiagnoseHLSLAvailability::ScannedDecls``). It might happen that a shader 
library has multiple shader entry points for different shader stages that all 
call into the same shared function. It is therefore important to record not 
just that a function has been scanned, but also in which shader stage context. 
This is done by using ``llvm::DenseMap`` that maps ``FunctionDecl *`` to a 
``unsigned`` bitmap that represents a set of shader stages (or environments) 
the function has been scanned for. The ``N``'th bit in the set is set if the 
function has been scanned in shader environment whose 
``HLSLShaderAttr::ShaderType`` integer value equals ``N``.
+
+The emitted diagnostic messages belong to ``hlsl-availability`` diagnostic 
group and are reported as errors by default. With 
``-Wno-error=hlsl-availability`` flang they become warning, making it relaxed 
HLSL diagnostics mode.
+
+Strict Diagnostic Mode
+--
+
+When strict HLSL availability diagnostic mode is enabled the compiler must 
report all HLSL API availab

[clang] [clang] Use constant rounding mode for floating literals (PR #90877)

2024-05-16 Thread Serge Pavlov via cfe-commits

https://github.com/spavloff closed 
https://github.com/llvm/llvm-project/pull/90877
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] f4066fa - [clang] Use constant rounding mode for floating literals (#90877)

2024-05-16 Thread via cfe-commits

Author: Serge Pavlov
Date: 2024-05-17T12:06:34+07:00
New Revision: f4066fa2dd21c65bf0e24a479634c9a2d276cf8e

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

LOG: [clang] Use constant rounding mode for floating literals (#90877)

Conversion of floating-point literal to binary representation must be
made using constant rounding mode, which can be changed using pragma
FENV_ROUND. For example, the literal "0.1F" should be representes by
either 0.09994 or 0.10001 depending on the rounding direction.

Added: 


Modified: 
clang/include/clang/Lex/LiteralSupport.h
clang/lib/Lex/LiteralSupport.cpp
clang/lib/Sema/SemaExpr.cpp
clang/test/AST/const-fpfeatures.c
clang/test/AST/const-fpfeatures.cpp

Removed: 




diff  --git a/clang/include/clang/Lex/LiteralSupport.h 
b/clang/include/clang/Lex/LiteralSupport.h
index 2ed42d1c5f9aa..705021fcfa5b1 100644
--- a/clang/include/clang/Lex/LiteralSupport.h
+++ b/clang/include/clang/Lex/LiteralSupport.h
@@ -118,12 +118,10 @@ class NumericLiteralParser {
   /// bits of the result and return true.  Otherwise, return false.
   bool GetIntegerValue(llvm::APInt &Val);
 
-  /// GetFloatValue - Convert this numeric literal to a floating value, using
-  /// the specified APFloat fltSemantics (specifying float, double, etc).
-  /// The optional bool isExact (passed-by-reference) has its value
-  /// set to true if the returned APFloat can represent the number in the
-  /// literal exactly, and false otherwise.
-  llvm::APFloat::opStatus GetFloatValue(llvm::APFloat &Result);
+  /// Convert this numeric literal to a floating value, using the specified
+  /// APFloat fltSemantics (specifying float, double, etc) and rounding mode.
+  llvm::APFloat::opStatus GetFloatValue(llvm::APFloat &Result,
+llvm::RoundingMode RM);
 
   /// GetFixedPointValue - Convert this numeric literal value into a
   /// scaled integer that represents this value. Returns true if an overflow

diff  --git a/clang/lib/Lex/LiteralSupport.cpp 
b/clang/lib/Lex/LiteralSupport.cpp
index 9c0cbea5052cb..3df0391bdda77 100644
--- a/clang/lib/Lex/LiteralSupport.cpp
+++ b/clang/lib/Lex/LiteralSupport.cpp
@@ -1520,7 +1520,8 @@ bool NumericLiteralParser::GetIntegerValue(llvm::APInt 
&Val) {
 }
 
 llvm::APFloat::opStatus
-NumericLiteralParser::GetFloatValue(llvm::APFloat &Result) {
+NumericLiteralParser::GetFloatValue(llvm::APFloat &Result,
+llvm::RoundingMode RM) {
   using llvm::APFloat;
 
   unsigned n = std::min(SuffixBegin - ThisTokBegin, ThisTokEnd - ThisTokBegin);
@@ -1534,8 +1535,7 @@ NumericLiteralParser::GetFloatValue(llvm::APFloat 
&Result) {
 Str = Buffer;
   }
 
-  auto StatusOrErr =
-  Result.convertFromString(Str, APFloat::rmNearestTiesToEven);
+  auto StatusOrErr = Result.convertFromString(Str, RM);
   assert(StatusOrErr && "Invalid floating point representation");
   return !errorToBool(StatusOrErr.takeError()) ? *StatusOrErr
: APFloat::opInvalidOp;

diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 274e1fb183534..e0aae6333e1a1 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -3699,7 +3699,10 @@ static Expr *BuildFloatingLiteral(Sema &S, 
NumericLiteralParser &Literal,
   using llvm::APFloat;
   APFloat Val(Format);
 
-  APFloat::opStatus result = Literal.GetFloatValue(Val);
+  llvm::RoundingMode RM = S.CurFPFeatures.getRoundingMode();
+  if (RM == llvm::RoundingMode::Dynamic)
+RM = llvm::RoundingMode::NearestTiesToEven;
+  APFloat::opStatus result = Literal.GetFloatValue(Val, RM);
 
   // Overflow is always an error, but underflow is only an error if
   // we underflowed to zero (APFloat reports denormals as underflow).

diff  --git a/clang/test/AST/const-fpfeatures.c 
b/clang/test/AST/const-fpfeatures.c
index 083350fdc8ce6..8dc3221b0638a 100644
--- a/clang/test/AST/const-fpfeatures.c
+++ b/clang/test/AST/const-fpfeatures.c
@@ -19,6 +19,9 @@ float FI1u = 0xU;
 float _Complex C1u = C0;
 // CHECK: @C1u = {{.*}} { float, float } { float 0x3FF02000, float 
0x3FF02000 }
 
+float FLu = 0.1F;
+// CHECK: @FLu = {{.*}} float 0x3FB9A000
+
 
 #pragma STDC FENV_ROUND FE_DOWNWARD
 
@@ -35,3 +38,6 @@ float FI1d = 0xU;
 
 float _Complex C1d = C0;
 // CHECK: @C1d = {{.*}} { float, float } { float 1.00e+00, float 
1.00e+00 }
+
+float FLd = 0.1F;
+// CHECK: @FLd = {{.*}} float 0x3FB98000

diff  --git a/clang/test/AST/const-fpfeatures.cpp 
b/clang/test/AST/const-fpfeatures.cpp
index 95eb613df7f07..5e903c8c0e874 100644
--- a/clang/test/AST/const-fpfeatures.cpp
+++ b/clang/test/AST/const-fpfeatures.cpp
@@ -79,3 +79,108 @@ float V7 = []() ->

[clang] a26fbf3 - [Sema] Use SmallString::empty (NFC)

2024-05-16 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2024-05-16T22:04:03-07:00
New Revision: a26fbf36a78a703be2da0744131a8d6ecbdb7c67

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

LOG: [Sema] Use SmallString::empty (NFC)

Added: 


Modified: 
clang/lib/Sema/SemaDeclAttr.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 777171f4f15f5..3760a4c917ad7 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -3645,7 +3645,7 @@ bool Sema::checkTargetClonesAttrString(
 llvm::sort(CurFeatures);
 SmallString<64> Res;
 for (auto &CurFeat : CurFeatures) {
-  if (!Res.equals(""))
+  if (!Res.empty())
 Res.append("+");
   Res.append(CurFeat);
 }



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


[clang] [llvm] [AMDGPU][WIP] Extend readlane, writelane and readfirstlane intrinsic lowering for generic types (PR #89217)

2024-05-16 Thread Vikram Hegde via cfe-commits


@@ -243,11 +243,16 @@ def VOP_READFIRSTLANE : VOPProfile <[i32, i32, untyped, 
untyped]> {
 // FIXME: Specify SchedRW for READFIRSTLANE_B32
 // TODO: There is VOP3 encoding also
 def V_READFIRSTLANE_B32 : VOP1_Pseudo <"v_readfirstlane_b32", 
VOP_READFIRSTLANE,
-   getVOP1Pat.ret, 1> {
+   [], 1> {
   let isConvergent = 1;
 }
 
+foreach vt = Reg32Types.types in {
+  def : GCNPat<(vt (AMDGPUreadfirstlane (vt VRegOrLdsSrc_32:$src0))),
+(V_READFIRSTLANE_B32 (vt VRegOrLdsSrc_32:$src0))

vikramRH wrote:

Do you think these changes are okay until I figure out root cause ?

https://github.com/llvm/llvm-project/pull/89217
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [compiler-rt] [lldb] [llvm] [mlir] [openmp] [polly] fix(python): fix comparison to None (PR #91857)

2024-05-16 Thread Mehdi Amini via cfe-commits

https://github.com/joker-eph approved this pull request.

If you can push this to main in separate commits (one per project as it was 
mentioned?), that'd be great!

https://github.com/llvm/llvm-project/pull/91857
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Implement provisional wording for CWG2398 regarding packs (PR #90820)

2024-05-16 Thread Mehdi Amini via cfe-commits

joker-eph wrote:

You're right, it's visible on the link I posted, the build was already broken! 
Somehow I fat-fingered and didn't hit the first red build but the third one!

https://github.com/llvm/llvm-project/pull/90820
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-cl][AST] Fix auto NTTP MSVC 1920+ mangling for pointer types (PR #92477)

2024-05-16 Thread Max Winkler via cfe-commits

https://github.com/MaxEW707 updated 
https://github.com/llvm/llvm-project/pull/92477

>From 139c51074b43623ea7b206080056823e216fedac Mon Sep 17 00:00:00 2001
From: MaxEW707 
Date: Thu, 16 May 2024 21:03:46 -0400
Subject: [PATCH 1/2] [clang-cl][AST] Fix auto NTTP MSVC 1920+ mangling

---
 clang/docs/ReleaseNotes.rst   |  7 +++
 clang/lib/AST/MicrosoftMangle.cpp | 63 ++-
 .../CodeGenCXX/mangle-ms-auto-templates.cpp   | 31 +
 3 files changed, 98 insertions(+), 3 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 65d191b6161a4..f0843fcb74531 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -83,6 +83,13 @@ ABI Changes in This Version
 - Fixed Microsoft calling convention when returning classes that have a deleted
   copy assignment operator. Such a class should be returned indirectly.
 
+- Fixed Microsoft name mangling for auto non-type template arguments of pointer
+  type for MSVC 1920+. This change resolves incompatibilities with code 
compiled
+  by MSVC 1920+ but will introduce incompatibilities with code compiled by
+  earlier versions of Clang unless such code is built with the compiler option
+  `-fms-compatibility-version=19.14` to imitate the MSVC 1914 mangling 
behavior.
+
+
 AST Dumping Potentially Breaking Changes
 
 
diff --git a/clang/lib/AST/MicrosoftMangle.cpp 
b/clang/lib/AST/MicrosoftMangle.cpp
index 36d611750ca48..627c4511f2816 100644
--- a/clang/lib/AST/MicrosoftMangle.cpp
+++ b/clang/lib/AST/MicrosoftMangle.cpp
@@ -372,6 +372,11 @@ class MicrosoftCXXNameMangler {
   void mangleMemberFunctionPointer(const CXXRecordDecl *RD,
const CXXMethodDecl *MD,
StringRef Prefix = "$");
+  void mangleFunctionPointer(const FunctionDecl *FD,
+ const NonTypeTemplateParmDecl *PD,
+ QualType TemplateArgType);
+  void mangleVarDecl(const VarDecl *VD, const NonTypeTemplateParmDecl *PD,
+ QualType TemplateArgType);
   void mangleMemberFunctionPointerInClassNTTP(const CXXRecordDecl *RD,
   const CXXMethodDecl *MD);
   void mangleVirtualMemPtrThunk(const CXXMethodDecl *MD,
@@ -799,6 +804,50 @@ MicrosoftCXXNameMangler::mangleMemberFunctionPointer(const 
CXXRecordDecl *RD,
 mangleNumber(VBTableOffset);
 }
 
+void MicrosoftCXXNameMangler::mangleFunctionPointer(
+const FunctionDecl *FD, const NonTypeTemplateParmDecl *PD,
+QualType TemplateArgType) {
+  //  ::= $1? 
+  //  ::= 
+  //
+  //  ::= $ M  1? 
+  Out << '$';
+
+  if (getASTContext().getLangOpts().isCompatibleWithMSVC(
+  LangOptions::MSVC2019) &&
+  PD && PD->getType()->getTypeClass() == Type::Auto &&
+  !TemplateArgType.isNull()) {
+Out << "M";
+mangleType(TemplateArgType, SourceRange(), QMM_Drop);
+  }
+
+  Out << "1?";
+  mangleName(FD);
+  mangleFunctionEncoding(FD, /*ShouldMangle=*/true);
+}
+
+void MicrosoftCXXNameMangler::mangleVarDecl(const VarDecl *VD,
+const NonTypeTemplateParmDecl *PD,
+QualType TemplateArgType) {
+  //  ::= $1? 
+  //  ::= 
+  //
+  //  ::= $ M  1? 
+  Out << '$';
+
+  if (getASTContext().getLangOpts().isCompatibleWithMSVC(
+  LangOptions::MSVC2019) &&
+  PD && PD->getType()->getTypeClass() == Type::Auto &&
+  !TemplateArgType.isNull()) {
+Out << "M";
+mangleType(TemplateArgType, SourceRange(), QMM_Drop);
+  }
+
+  Out << "1?";
+  mangleName(VD);
+  mangleVariableEncoding(VD);
+}
+
 void MicrosoftCXXNameMangler::mangleMemberFunctionPointerInClassNTTP(
 const CXXRecordDecl *RD, const CXXMethodDecl *MD) {
   //  ::= 
@@ -1552,6 +1601,9 @@ void MicrosoftCXXNameMangler::mangleIntegerLiteral(
 const llvm::APSInt &Value, const NonTypeTemplateParmDecl *PD,
 QualType TemplateArgType) {
   //  ::= $0 
+  //  ::= 
+  //
+  //  ::= $ M  0 
   Out << "$";
 
   // Since MSVC 2019, add 'M[]' after '$' for auto template parameter 
when
@@ -1629,8 +1681,11 @@ void MicrosoftCXXNameMangler::mangleTemplateArg(const 
TemplateDecl *TD,
   //::= 
   //::= 
   //::= $ 
+  //::= $ 
   //::= 
   //
+  //  ::= M  
+  //
   //  ::= 0# integer
   //  ::= 1  # address of D
   //  ::= 2  * @ # struct
@@ -1678,15 +1733,17 @@ void MicrosoftCXXNameMangler::mangleTemplateArg(const 
TemplateDecl *TD,
 mangleMemberFunctionPointer(
 MD->getParent()->getMostRecentNonInjectedDecl(), MD);
   } else {
-Out << "$1?";
-mangleName(FD);
-mangleFunctionEncoding(FD, /*ShouldMangle=*/true);
+mangleFunctionPointer(FD, cast(Parm),
+  TA.getParamTypeFor

[clang-tools-extra] [run-clang-tidy.py] Refactor, add progress indicator, add type hints (PR #89490)

2024-05-16 Thread Piotr Zegar via cfe-commits

PiotrZSL wrote:

@nicovank I think that code is fine, will re-check it today. We could always 
think about something else later.

https://github.com/llvm/llvm-project/pull/89490
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Fix a bug in formatting goto labels in macros (PR #92494)

2024-05-16 Thread Owen Pan via cfe-commits

https://github.com/owenca edited https://github.com/llvm/llvm-project/pull/92494
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Fix a regression in annotating goto labels (PR #92494)

2024-05-16 Thread Owen Pan via cfe-commits

https://github.com/owenca updated 
https://github.com/llvm/llvm-project/pull/92494

>From d9f113101028c68465e8befe7db1d4c206daa535 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Thu, 16 May 2024 20:49:17 -0700
Subject: [PATCH] [clang-format] Fix a bug in formatting goto labels in macros

Fixes #92300.
---
 clang/lib/Format/UnwrappedLineParser.cpp  |  9 ++---
 clang/unittests/Format/FormatTest.cpp |  8 
 clang/unittests/Format/TokenAnnotatorTest.cpp | 13 +
 3 files changed, 23 insertions(+), 7 deletions(-)

diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index b15a87327240b..3dd10f6bd2b31 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -1189,12 +1189,6 @@ void UnwrappedLineParser::parsePPDefine() {
 return;
   }
 
-  if (FormatTok->is(tok::identifier) &&
-  Tokens->peekNextToken()->is(tok::colon)) {
-nextToken();
-nextToken();
-  }
-
   // Errors during a preprocessor directive can only affect the layout of the
   // preprocessor directive, and thus we ignore them. An alternative approach
   // would be to use the same approach we use on the file level (no
@@ -1681,7 +1675,8 @@ void UnwrappedLineParser::parseStructuralElement(
 if (!Style.isJavaScript() && !Style.isVerilog() && !Style.isTableGen() &&
 Tokens->peekNextToken()->is(tok::colon) && !Line->MustBeDeclaration) {
   nextToken();
-  Line->Tokens.begin()->Tok->MustBreakBefore = true;
+  if (!Line->InMacroBody || CurrentLines->size() > 1)
+Line->Tokens.begin()->Tok->MustBreakBefore = true;
   FormatTok->setFinalizedType(TT_GotoLabelColon);
   parseLabel(!Style.IndentGotoLabels);
   if (HasLabel)
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 6f57f10e12e88..2f0c0f0266774 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -3124,6 +3124,7 @@ TEST_F(FormatTest, FormatsLabels) {
"g();\n"
"  }\n"
"}");
+
   FormatStyle Style = getLLVMStyle();
   Style.IndentGotoLabels = false;
   verifyFormat("void f() {\n"
@@ -3163,6 +3164,13 @@ TEST_F(FormatTest, FormatsLabels) {
"  }\n"
"}",
Style);
+
+  Style.ColumnLimit = 15;
+  verifyFormat("#define FOO   \\\n"
+   "label:\\\n"
+   "  break;",
+   Style);
+
   // The opening brace may either be on the same unwrapped line as the colon or
   // on a separate one. The formatter should recognize both.
   Style = getLLVMStyle();
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index aadfa6dc0165c..83d9cc766ae5f 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -2581,15 +2581,28 @@ TEST_F(TokenAnnotatorTest, UnderstandsLabels) {
   auto Tokens = annotate("{ x: break; }");
   ASSERT_EQ(Tokens.size(), 7u) << Tokens;
   EXPECT_TOKEN(Tokens[2], tok::colon, TT_GotoLabelColon);
+
   Tokens = annotate("{ case x: break; }");
   ASSERT_EQ(Tokens.size(), 8u) << Tokens;
   EXPECT_TOKEN(Tokens[3], tok::colon, TT_CaseLabelColon);
+
   Tokens = annotate("{ x: { break; } }");
   ASSERT_EQ(Tokens.size(), 9u) << Tokens;
   EXPECT_TOKEN(Tokens[2], tok::colon, TT_GotoLabelColon);
+
   Tokens = annotate("{ case x: { break; } }");
   ASSERT_EQ(Tokens.size(), 10u) << Tokens;
   EXPECT_TOKEN(Tokens[3], tok::colon, TT_CaseLabelColon);
+
+  Tokens = annotate("#define FOO label:");
+  ASSERT_EQ(Tokens.size(), 6u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::colon, TT_GotoLabelColon);
+
+  Tokens = annotate("#define FOO \\\n"
+"label: \\\n"
+"  break;");
+  ASSERT_EQ(Tokens.size(), 8u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::colon, TT_GotoLabelColon);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandsNestedBlocks) {

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


[clang] [clang-format] Fix a regression in annotating goto labels (PR #92494)

2024-05-16 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-format

Author: Owen Pan (owenca)


Changes

Fixes #92300.

---
Full diff: https://github.com/llvm/llvm-project/pull/92494.diff


2 Files Affected:

- (modified) clang/lib/Format/UnwrappedLineParser.cpp (+2-7) 
- (modified) clang/unittests/Format/TokenAnnotatorTest.cpp (+13) 


``diff
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index b15a87327240b..3dd10f6bd2b31 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -1189,12 +1189,6 @@ void UnwrappedLineParser::parsePPDefine() {
 return;
   }
 
-  if (FormatTok->is(tok::identifier) &&
-  Tokens->peekNextToken()->is(tok::colon)) {
-nextToken();
-nextToken();
-  }
-
   // Errors during a preprocessor directive can only affect the layout of the
   // preprocessor directive, and thus we ignore them. An alternative approach
   // would be to use the same approach we use on the file level (no
@@ -1681,7 +1675,8 @@ void UnwrappedLineParser::parseStructuralElement(
 if (!Style.isJavaScript() && !Style.isVerilog() && !Style.isTableGen() &&
 Tokens->peekNextToken()->is(tok::colon) && !Line->MustBeDeclaration) {
   nextToken();
-  Line->Tokens.begin()->Tok->MustBreakBefore = true;
+  if (!Line->InMacroBody || CurrentLines->size() > 1)
+Line->Tokens.begin()->Tok->MustBreakBefore = true;
   FormatTok->setFinalizedType(TT_GotoLabelColon);
   parseLabel(!Style.IndentGotoLabels);
   if (HasLabel)
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index aadfa6dc0165c..d9c6e8cc1c877 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -2581,15 +2581,28 @@ TEST_F(TokenAnnotatorTest, UnderstandsLabels) {
   auto Tokens = annotate("{ x: break; }");
   ASSERT_EQ(Tokens.size(), 7u) << Tokens;
   EXPECT_TOKEN(Tokens[2], tok::colon, TT_GotoLabelColon);
+
   Tokens = annotate("{ case x: break; }");
   ASSERT_EQ(Tokens.size(), 8u) << Tokens;
   EXPECT_TOKEN(Tokens[3], tok::colon, TT_CaseLabelColon);
+
   Tokens = annotate("{ x: { break; } }");
   ASSERT_EQ(Tokens.size(), 9u) << Tokens;
   EXPECT_TOKEN(Tokens[2], tok::colon, TT_GotoLabelColon);
+
   Tokens = annotate("{ case x: { break; } }");
   ASSERT_EQ(Tokens.size(), 10u) << Tokens;
   EXPECT_TOKEN(Tokens[3], tok::colon, TT_CaseLabelColon);
+
+  Tokens = annotate("#define FOO label:");
+  ASSERT_EQ(Tokens.size(), 6u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::colon, TT_GotoLabelColon);
+
+  Tokens = annotate("#define FOO \\\n"
+"  label:\\\n"
+"  break;");
+  ASSERT_EQ(Tokens.size(), 8u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::colon, TT_GotoLabelColon);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandsNestedBlocks) {

``




https://github.com/llvm/llvm-project/pull/92494
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Fix a regression in annotating goto labels (PR #92494)

2024-05-16 Thread Owen Pan via cfe-commits

https://github.com/owenca created 
https://github.com/llvm/llvm-project/pull/92494

Fixes #92300.

>From 530b15d68c66b0f1414329a8e190b27c2e6bf106 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Thu, 16 May 2024 20:49:17 -0700
Subject: [PATCH] [clang-format] Fix a regression in annotating goto labels

Fixes #92300.
---
 clang/lib/Format/UnwrappedLineParser.cpp  |  9 ++---
 clang/unittests/Format/TokenAnnotatorTest.cpp | 13 +
 2 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index b15a87327240b..3dd10f6bd2b31 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -1189,12 +1189,6 @@ void UnwrappedLineParser::parsePPDefine() {
 return;
   }
 
-  if (FormatTok->is(tok::identifier) &&
-  Tokens->peekNextToken()->is(tok::colon)) {
-nextToken();
-nextToken();
-  }
-
   // Errors during a preprocessor directive can only affect the layout of the
   // preprocessor directive, and thus we ignore them. An alternative approach
   // would be to use the same approach we use on the file level (no
@@ -1681,7 +1675,8 @@ void UnwrappedLineParser::parseStructuralElement(
 if (!Style.isJavaScript() && !Style.isVerilog() && !Style.isTableGen() &&
 Tokens->peekNextToken()->is(tok::colon) && !Line->MustBeDeclaration) {
   nextToken();
-  Line->Tokens.begin()->Tok->MustBreakBefore = true;
+  if (!Line->InMacroBody || CurrentLines->size() > 1)
+Line->Tokens.begin()->Tok->MustBreakBefore = true;
   FormatTok->setFinalizedType(TT_GotoLabelColon);
   parseLabel(!Style.IndentGotoLabels);
   if (HasLabel)
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index aadfa6dc0165c..d9c6e8cc1c877 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -2581,15 +2581,28 @@ TEST_F(TokenAnnotatorTest, UnderstandsLabels) {
   auto Tokens = annotate("{ x: break; }");
   ASSERT_EQ(Tokens.size(), 7u) << Tokens;
   EXPECT_TOKEN(Tokens[2], tok::colon, TT_GotoLabelColon);
+
   Tokens = annotate("{ case x: break; }");
   ASSERT_EQ(Tokens.size(), 8u) << Tokens;
   EXPECT_TOKEN(Tokens[3], tok::colon, TT_CaseLabelColon);
+
   Tokens = annotate("{ x: { break; } }");
   ASSERT_EQ(Tokens.size(), 9u) << Tokens;
   EXPECT_TOKEN(Tokens[2], tok::colon, TT_GotoLabelColon);
+
   Tokens = annotate("{ case x: { break; } }");
   ASSERT_EQ(Tokens.size(), 10u) << Tokens;
   EXPECT_TOKEN(Tokens[3], tok::colon, TT_CaseLabelColon);
+
+  Tokens = annotate("#define FOO label:");
+  ASSERT_EQ(Tokens.size(), 6u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::colon, TT_GotoLabelColon);
+
+  Tokens = annotate("#define FOO \\\n"
+"  label:\\\n"
+"  break;");
+  ASSERT_EQ(Tokens.size(), 8u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::colon, TT_GotoLabelColon);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandsNestedBlocks) {

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


[clang] [libcxx] [lldb] [llvm] [mlir] [BOLT][BAT] Add entries for deleted basic blocks (PR #91906)

2024-05-16 Thread Amir Ayupov via cfe-commits

https://github.com/aaupov edited https://github.com/llvm/llvm-project/pull/91906
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [lldb] [llvm] [BOLT][NFC] Rename DataAggregator::BranchInfo to TakenBranchInfo (PR #92017)

2024-05-16 Thread Amir Ayupov via cfe-commits

https://github.com/aaupov closed https://github.com/llvm/llvm-project/pull/92017
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [lldb] [llvm] [BOLT][NFC] Rename DataAggregator::BranchInfo to TakenBranchInfo (PR #92017)

2024-05-16 Thread Amir Ayupov via cfe-commits

https://github.com/aaupov edited https://github.com/llvm/llvm-project/pull/92017
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [C++23] [CLANG] Adding C++23 constexpr math functions: fmin, fmax and frexp. (PR #88978)

2024-05-16 Thread Hubert Tong via cfe-commits

https://github.com/hubert-reinterpretcast edited 
https://github.com/llvm/llvm-project/pull/88978
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [compiler-rt] [lldb] [llvm] [mlir] [openmp] [polly] fix(python): fix comparison to None (PR #91857)

2024-05-16 Thread Jonas Devlieghere via cfe-commits

https://github.com/JDevlieghere commented:

This should really be broken up into separate PRs per subproject. One large PR 
like this makes reviewing harder and causes unnecessary churn in the case that 
this gets reverted.

https://github.com/llvm/llvm-project/pull/91857
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Fix a regression in annotating struct braces (PR #92352)

2024-05-16 Thread Owen Pan via cfe-commits

https://github.com/owenca closed https://github.com/llvm/llvm-project/pull/92352
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 88d351e - [clang-format] Fix a regression in annotating struct braces (#92352)

2024-05-16 Thread via cfe-commits

Author: Owen Pan
Date: 2024-05-16T19:24:35-07:00
New Revision: 88d351e2e62d2ff291f3e6dea6b7e425f683285b

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

LOG: [clang-format] Fix a regression in annotating struct braces (#92352)

Fixes #92350.

Added: 


Modified: 
clang/lib/Format/UnwrappedLineParser.cpp
clang/unittests/Format/TokenAnnotatorTest.cpp

Removed: 




diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 2236a49e4b765..b15a87327240b 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -4008,8 +4008,6 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) {
   };
 
   if (FormatTok->isOneOf(tok::colon, tok::less)) {
-if (FormatTok->is(tok::colon))
-  IsDerived = true;
 int AngleNestingLevel = 0;
 do {
   if (FormatTok->is(tok::less))
@@ -4017,9 +4015,13 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) {
   else if (FormatTok->is(tok::greater))
 --AngleNestingLevel;
 
-  if (AngleNestingLevel == 0 && FormatTok->is(tok::l_paren) &&
-  IsNonMacroIdentifier(FormatTok->Previous)) {
-break;
+  if (AngleNestingLevel == 0) {
+if (FormatTok->is(tok::colon)) {
+  IsDerived = true;
+} else if (FormatTok->is(tok::l_paren) &&
+   IsNonMacroIdentifier(FormatTok->Previous)) {
+  break;
+}
   }
   if (FormatTok->is(tok::l_brace)) {
 if (AngleNestingLevel == 0 && IsListInitialization())

diff  --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 51b475d37977e..aadfa6dc0165c 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -2903,6 +2903,11 @@ TEST_F(TokenAnnotatorTest, BraceKind) {
   EXPECT_BRACE_KIND(Tokens[5], BK_Block);
   EXPECT_BRACE_KIND(Tokens[6], BK_Block);
 
+  Tokens = annotate("struct Foo : Base {};");
+  ASSERT_EQ(Tokens.size(), 11u) << Tokens;
+  EXPECT_BRACE_KIND(Tokens[7], BK_Block);
+  EXPECT_BRACE_KIND(Tokens[8], BK_Block);
+
   Tokens = annotate("struct Foo final {};");
   ASSERT_EQ(Tokens.size(), 7u) << Tokens;
   EXPECT_BRACE_KIND(Tokens[3], BK_Block);



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


[clang] [flang] [flang][driver] Remove Fortain_main static library from linking stages (PR #75816)

2024-05-16 Thread via cfe-commits

h-vetinari wrote:

For anyone (like me) having to deal with correctly linking Fortran_main with 
flang 18+, it's worth noting that much of this got removed again in 
https://github.com/llvm/llvm-project/commit/8d5386669ed63548daf1bee415596582d6d78d7d.

https://github.com/llvm/llvm-project/pull/75816
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 8fe39e6 - [clang-format] Don't always break before << between string literals (#92214)

2024-05-16 Thread via cfe-commits

Author: Owen Pan
Date: 2024-05-16T19:23:47-07:00
New Revision: 8fe39e64c0ef0a1aefce3c1187c5822343caeedd

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

LOG: [clang-format] Don't always break before << between string literals 
(#92214)

Instead, leave the line wrapping as is.

Fixes #43887.
Fixes #44363.

Added: 


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

Removed: 




diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index d0aa0838423e4..7c4c76a91f2c5 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -5601,10 +5601,13 @@ bool TokenAnnotator::mustBreakBefore(const 
AnnotatedLine &Line,
 return true;
   if (Left.IsUnterminatedLiteral)
 return true;
-  if (Right.is(tok::lessless) && AfterRight && Left.is(tok::string_literal) &&
+
+  if (BeforeLeft && BeforeLeft->is(tok::lessless) &&
+  Left.is(tok::string_literal) && Right.is(tok::lessless) && AfterRight &&
   AfterRight->is(tok::string_literal)) {
-return true;
+return Right.NewlinesBefore > 0;
   }
+
   if (Right.is(TT_RequiresClause)) {
 switch (Style.RequiresClausePosition) {
 case FormatStyle::RCPS_OwnLine:

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index e6f8e4a06515e..6f57f10e12e88 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -10539,6 +10539,17 @@ TEST_F(FormatTest, KeepStringLabelValuePairsOnALine) {
   "  bbb);");
 }
 
+TEST_F(FormatTest, WrapBeforeInsertionOperatorbetweenStringLiterals) {
+  verifyFormat("QStringList() << \"foo\" << \"bar\";");
+
+  verifyNoChange("QStringList() << \"foo\"\n"
+ "  << \"bar\";");
+
+  verifyFormat("log_error(log, \"foo\" << \"bar\");",
+   "log_error(log, \"foo\"\n"
+   "   << \"bar\");");
+}
+
 TEST_F(FormatTest, UnderstandsEquals) {
   verifyFormat(
   "a =\n"



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


[clang] [clang-format] Don't always break before << between string literals (PR #92214)

2024-05-16 Thread Owen Pan via cfe-commits

https://github.com/owenca closed https://github.com/llvm/llvm-project/pull/92214
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-cl][AST] Fix auto NTTP MSVC 1920+ mangling for pointer types (PR #92477)

2024-05-16 Thread Max Winkler via cfe-commits

https://github.com/MaxEW707 updated 
https://github.com/llvm/llvm-project/pull/92477

>From 7b73c2b907b09ec87197e9613c4abc27ff52083b Mon Sep 17 00:00:00 2001
From: MaxEW707 
Date: Thu, 16 May 2024 21:03:46 -0400
Subject: [PATCH 1/2] [clang-cl][AST] Fix auto NTTP MSVC 1920+ mangling

---
 clang/docs/ReleaseNotes.rst   |  7 +++
 clang/lib/AST/MicrosoftMangle.cpp | 63 ++-
 .../CodeGenCXX/mangle-ms-auto-templates.cpp   | 31 +
 3 files changed, 98 insertions(+), 3 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index a3c8e4141ca54..80ea74ed295f9 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -79,6 +79,13 @@ ABI Changes in This Version
 - Fixed Microsoft calling convention when returning classes that have a deleted
   copy assignment operator. Such a class should be returned indirectly.
 
+- Fixed Microsoft name mangling for auto non-type template arguments of pointer
+  type for MSVC 1920+. This change resolves incompatibilities with code 
compiled
+  by MSVC 1920+ but will introduce incompatibilities with code compiled by
+  earlier versions of Clang unless such code is built with the compiler option
+  `-fms-compatibility-version=19.14` to imitate the MSVC 1914 mangling 
behavior.
+
+
 AST Dumping Potentially Breaking Changes
 
 
diff --git a/clang/lib/AST/MicrosoftMangle.cpp 
b/clang/lib/AST/MicrosoftMangle.cpp
index 36d611750ca48..627c4511f2816 100644
--- a/clang/lib/AST/MicrosoftMangle.cpp
+++ b/clang/lib/AST/MicrosoftMangle.cpp
@@ -372,6 +372,11 @@ class MicrosoftCXXNameMangler {
   void mangleMemberFunctionPointer(const CXXRecordDecl *RD,
const CXXMethodDecl *MD,
StringRef Prefix = "$");
+  void mangleFunctionPointer(const FunctionDecl *FD,
+ const NonTypeTemplateParmDecl *PD,
+ QualType TemplateArgType);
+  void mangleVarDecl(const VarDecl *VD, const NonTypeTemplateParmDecl *PD,
+ QualType TemplateArgType);
   void mangleMemberFunctionPointerInClassNTTP(const CXXRecordDecl *RD,
   const CXXMethodDecl *MD);
   void mangleVirtualMemPtrThunk(const CXXMethodDecl *MD,
@@ -799,6 +804,50 @@ MicrosoftCXXNameMangler::mangleMemberFunctionPointer(const 
CXXRecordDecl *RD,
 mangleNumber(VBTableOffset);
 }
 
+void MicrosoftCXXNameMangler::mangleFunctionPointer(
+const FunctionDecl *FD, const NonTypeTemplateParmDecl *PD,
+QualType TemplateArgType) {
+  //  ::= $1? 
+  //  ::= 
+  //
+  //  ::= $ M  1? 
+  Out << '$';
+
+  if (getASTContext().getLangOpts().isCompatibleWithMSVC(
+  LangOptions::MSVC2019) &&
+  PD && PD->getType()->getTypeClass() == Type::Auto &&
+  !TemplateArgType.isNull()) {
+Out << "M";
+mangleType(TemplateArgType, SourceRange(), QMM_Drop);
+  }
+
+  Out << "1?";
+  mangleName(FD);
+  mangleFunctionEncoding(FD, /*ShouldMangle=*/true);
+}
+
+void MicrosoftCXXNameMangler::mangleVarDecl(const VarDecl *VD,
+const NonTypeTemplateParmDecl *PD,
+QualType TemplateArgType) {
+  //  ::= $1? 
+  //  ::= 
+  //
+  //  ::= $ M  1? 
+  Out << '$';
+
+  if (getASTContext().getLangOpts().isCompatibleWithMSVC(
+  LangOptions::MSVC2019) &&
+  PD && PD->getType()->getTypeClass() == Type::Auto &&
+  !TemplateArgType.isNull()) {
+Out << "M";
+mangleType(TemplateArgType, SourceRange(), QMM_Drop);
+  }
+
+  Out << "1?";
+  mangleName(VD);
+  mangleVariableEncoding(VD);
+}
+
 void MicrosoftCXXNameMangler::mangleMemberFunctionPointerInClassNTTP(
 const CXXRecordDecl *RD, const CXXMethodDecl *MD) {
   //  ::= 
@@ -1552,6 +1601,9 @@ void MicrosoftCXXNameMangler::mangleIntegerLiteral(
 const llvm::APSInt &Value, const NonTypeTemplateParmDecl *PD,
 QualType TemplateArgType) {
   //  ::= $0 
+  //  ::= 
+  //
+  //  ::= $ M  0 
   Out << "$";
 
   // Since MSVC 2019, add 'M[]' after '$' for auto template parameter 
when
@@ -1629,8 +1681,11 @@ void MicrosoftCXXNameMangler::mangleTemplateArg(const 
TemplateDecl *TD,
   //::= 
   //::= 
   //::= $ 
+  //::= $ 
   //::= 
   //
+  //  ::= M  
+  //
   //  ::= 0# integer
   //  ::= 1  # address of D
   //  ::= 2  * @ # struct
@@ -1678,15 +1733,17 @@ void MicrosoftCXXNameMangler::mangleTemplateArg(const 
TemplateDecl *TD,
 mangleMemberFunctionPointer(
 MD->getParent()->getMostRecentNonInjectedDecl(), MD);
   } else {
-Out << "$1?";
-mangleName(FD);
-mangleFunctionEncoding(FD, /*ShouldMangle=*/true);
+mangleFunctionPointer(FD, cast(Parm),
+  TA.getParamTypeFor

[clang] HLSL availability diagnostics design doc (PR #92207)

2024-05-16 Thread Helena Kotas via cfe-commits


@@ -0,0 +1,53 @@
+=
+HLSL Availability Diagnostics
+=
+
+.. contents::
+   :local:
+
+Introduction
+
+
+HLSL availability diagnostics emits errors or warning when unavailable shader 
APIs are used. Unavailable shader APIs are APIs that are exposed in HLSL code 
but are not available in the target shader stage or shader model version.

hekota wrote:

Done.

https://github.com/llvm/llvm-project/pull/92207
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] HLSL availability diagnostics design doc (PR #92207)

2024-05-16 Thread Helena Kotas via cfe-commits

https://github.com/hekota updated 
https://github.com/llvm/llvm-project/pull/92207

>From 3df0ba0fd2171a0115427bc6ba5e3f8e84831747 Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Tue, 14 May 2024 19:06:59 -0700
Subject: [PATCH 1/6] HLSL Availability Diagnostics Design Document - initial
 commit

---
 clang/docs/HLSL/AvailabilityDiagnostics.rst | 50 +
 clang/docs/HLSL/HLSLDocs.rst|  1 +
 2 files changed, 51 insertions(+)
 create mode 100644 clang/docs/HLSL/AvailabilityDiagnostics.rst

diff --git a/clang/docs/HLSL/AvailabilityDiagnostics.rst 
b/clang/docs/HLSL/AvailabilityDiagnostics.rst
new file mode 100644
index 0..218047495e6b9
--- /dev/null
+++ b/clang/docs/HLSL/AvailabilityDiagnostics.rst
@@ -0,0 +1,50 @@
+=
+HLSL Availability Diagnostics
+=
+
+.. contents::
+   :local:
+
+Introduction
+
+
+HLSL availability diagnostics emits errors or warning when unavailable shader 
APIs are used. Unavailable shader APIs are APIs that are exposed in HLSL code 
but are not available in the target shader stage or shader model version.
+
+There are three modes of HLSL availability diagnostic:
+1. **Default mode** - compiler emits an error when an unavailable shader API 
is found in a code that is reachable from the shader entry point function or 
from an exported library function (when compiling a shader library)
+2. **Relaxed mode** - same as default mode except the compiler emits a 
warning. This mode is enabled by ``-Wno-error=hlsl-availability``.
+3. **Strict mode** - compiler emits an error when when an unavailable API is 
found in parsed code regardless of whether it can be reached from the shader 
entry point or exported functions, or not. This mode is enabled by 
``-fhlsl-strict-diagnostics``.
+
+Implementation Details
+==
+
+Environment Parameter
+-
+
+In order to encode API availability based on the shader model version and 
shader model stage a new ``environment`` parameter was added to the existing 
Clang ``availability`` attribute. 
+
+The values allowed for this parameter are a subset of values allowed as the 
``llvm::Triple`` environment component. If the environment parameters is 
present, the declared availability attribute applies only to targets with the 
same platform and environment.
+
+Default and Relaxed Diagnostic Modes
+
+
+This mode is implemeted in ``DiagnoseHLSLAvailability`` class in 
``SemaHLSL.cpp`` and it is invoked after the whole translation unit is parsed 
(from ``Sema::ActOnEndOfTranslationUnit``). The implementation iterates over 
all shader entry points and exported library functions in the translation unit 
and performs an AST traversal of each function body.
+
+When a reference to another function is found and it has a body, the AST of 
the referenced function is also scanned. This chain of AST traversals will 
reach all of the code that is reachable from the initial shader entry point or 
exported library function.
+
+All shader APIs have an availability attribute that specifies the shader model 
version (and environment, if applicable) when this API was first 
introduced.When a reference to a function without a definition is found and it 
has an availability attribute, the version of the attribute is checked against 
the target shader model version and shader stage (if shader stage context is 
known), and an appropriate diagnostic is generated as needed.
+
+All shader entry functions have ``HLSLShaderAttr`` attribute that specifies 
what type of shader this function represents. However, for exported library 
functions the target shader stage is unknown, so in this case the HLSL API 
availability will be only checked against the shader model version.
+
+A list of functions that were already scanned is kept in order to avoid 
duplicate scans and diagnostics (see 
``DiagnoseHLSLAvailability::ScannedDecls``). It might happen that a shader 
library has multiple shader entry points for different shader stages that all 
call into the same shared function. It is therefore important to record not 
just that a function has been scanned, but also in which shader stage context. 
This is done by using ``llvm::DenseMap`` that maps ``FunctionDecl *`` to a 
``unsigned`` bitmap that represents a set of shader stages (or environments) 
the function has been scanned for. The ``N``'th bit in the set is set if the 
function has been scanned in shader environment whose 
``HLSLShaderAttr::ShaderType`` integer value equals ``N``.
+
+The emitted diagnostic messages belong to ``hlsl-availability`` diagnostic 
group and are reported as errors by default. With 
``-Wno-error=hlsl-availability`` flang they become warning, making it relaxed 
HLSL diagnostics mode.
+
+Strict Diagnostic Mode
+--
+
+When strict HLSL availability diagnostic mode is enabled the compiler must 
report all HLSL API availab

[clang] [Serialization] Read the initializer for interesting static variables before consuming it (PR #92353)

2024-05-16 Thread Chuanqi Xu via cfe-commits

https://github.com/ChuanqiXu9 updated 
https://github.com/llvm/llvm-project/pull/92353

>From 699da64855f147708f153c30177a1d02a4e014f7 Mon Sep 17 00:00:00 2001
From: Chuanqi Xu 
Date: Wed, 15 May 2024 12:37:16 +0800
Subject: [PATCH 1/2] [Serialization] Read the initializer for interesting
 static variables before consuming it

Close https://github.com/llvm/llvm-project/issues/91418

Since we load the variable's initializers lazily, it'd be
problematic if the initializers dependent on each other. So here we try to load
the initializers of static variables to make sure they are passed to
code generator by order. If we read any thing interesting, we would
consume that before emitting the current declaration.
---
 clang/lib/Serialization/ASTReaderDecl.cpp|  29 ++-
 clang/test/Modules/pr91418.cppm  |  67 +
 clang/test/OpenMP/nvptx_lambda_capturing.cpp | 246 +--
 3 files changed, 216 insertions(+), 126 deletions(-)
 create mode 100644 clang/test/Modules/pr91418.cppm

diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp 
b/clang/lib/Serialization/ASTReaderDecl.cpp
index 0c647086e304a..a6254b70560c3 100644
--- a/clang/lib/Serialization/ASTReaderDecl.cpp
+++ b/clang/lib/Serialization/ASTReaderDecl.cpp
@@ -4186,12 +4186,35 @@ void ASTReader::PassInterestingDeclsToConsumer() {
 GetDecl(ID);
   EagerlyDeserializedDecls.clear();
 
-  while (!PotentiallyInterestingDecls.empty()) {
-Decl *D = PotentiallyInterestingDecls.front();
-PotentiallyInterestingDecls.pop_front();
+  auto ConsumingPotentialInterestingDecls = [this]() {
+while (!PotentiallyInterestingDecls.empty()) {
+  Decl *D = PotentiallyInterestingDecls.front();
+  PotentiallyInterestingDecls.pop_front();
+  if (isConsumerInterestedIn(D))
+PassInterestingDeclToConsumer(D);
+}
+  };
+  std::deque MaybeInterestingDecls =
+  std::move(PotentiallyInterestingDecls);
+  assert(PotentiallyInterestingDecls.empty());
+  while (!MaybeInterestingDecls.empty()) {
+Decl *D = MaybeInterestingDecls.front();
+MaybeInterestingDecls.pop_front();
+// Since we load the variable's initializers lazily, it'd be problematic
+// if the initializers dependent on each other. So here we try to load the
+// initializers of static variables to make sure they are passed to code
+// generator by order. If we read anything interesting, we would consume
+// that before emitting the current declaration.
+if (auto *VD = dyn_cast(D);
+VD && VD->isFileVarDecl() && !VD->isExternallyVisible())
+  VD->getInit();
+ConsumingPotentialInterestingDecls();
 if (isConsumerInterestedIn(D))
   PassInterestingDeclToConsumer(D);
   }
+
+  // If we add any new potential interesting decl in the last call, consume it.
+  ConsumingPotentialInterestingDecls();
 }
 
 void ASTReader::loadDeclUpdateRecords(PendingUpdateRecord &Record) {
diff --git a/clang/test/Modules/pr91418.cppm b/clang/test/Modules/pr91418.cppm
new file mode 100644
index 0..33fec992439d6
--- /dev/null
+++ b/clang/test/Modules/pr91418.cppm
@@ -0,0 +1,67 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 -x c++-header 
%t/foo.h \
+// RUN: -emit-pch -o %t/foo.pch
+// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 %t/use.cpp 
-include-pch \
+// RUN: %t/foo.pch -emit-llvm -o - | FileCheck %t/use.cpp
+
+//--- foo.h
+#ifndef FOO_H
+#define FOO_H
+typedef float __m128 __attribute__((__vector_size__(16), __aligned__(16)));
+
+static __inline__ __m128 __attribute__((__always_inline__, 
__min_vector_width__(128)))
+_mm_setr_ps(float __z, float __y, float __x, float __w)
+{
+  return __extension__ (__m128){ __z, __y, __x, __w };
+}
+
+typedef __m128 VR;
+
+inline VR MakeVR( float X, float Y, float Z, float W )
+{
+ return _mm_setr_ps( X, Y, Z, W );
+}
+
+extern "C" float sqrtf(float);
+
+namespace VectorSinConstantsSSE
+{
+  float a = (16 * sqrtf(0.225f));
+  VR A = MakeVR(a, a, a, a);
+  static const float b = (16 * sqrtf(0.225f));
+  static const VR B = MakeVR(b, b, b, b);
+}
+
+#endif // FOO_H
+
+//--- use.cpp
+#include "foo.h"
+float use() {
+return VectorSinConstantsSSE::A[0] + VectorSinConstantsSSE::A[1] +
+   VectorSinConstantsSSE::A[2] + VectorSinConstantsSSE::A[3] +
+   VectorSinConstantsSSE::B[0] + VectorSinConstantsSSE::B[1] +
+   VectorSinConstantsSSE::B[2] + VectorSinConstantsSSE::B[3];
+}
+
+// CHECK: define{{.*}}@__cxx_global_var_init(
+// CHECK: store{{.*}}[[a_RESULT:%[a-zA-Z0-9]+]], ptr 
@_ZN21VectorSinConstantsSSE1aE
+
+// CHECK: define{{.*}}@__cxx_global_var_init.1(
+// CHECK: [[A_CALL:%[a-zA-Z0-9]+]] = call{{.*}}@_Z6MakeVR(
+// CHECK: store{{.*}}[[A_CALL]], ptr @_ZN21VectorSinConstantsSSE1AE
+
+// CHECK: define{{.*}}@__cxx_global_var_init.2(
+// CHECK: [[B_CALL:%[a-zA-Z0-9]+]] = call{{.*}}@_Z6MakeVR(
+// CHECK: store{{.*}}[[B_CALL]], ptr @_ZN21VectorSinConstantsSSE

[clang] HLSL availability diagnostics design doc (PR #92207)

2024-05-16 Thread Helena Kotas via cfe-commits

https://github.com/hekota updated 
https://github.com/llvm/llvm-project/pull/92207

>From 3df0ba0fd2171a0115427bc6ba5e3f8e84831747 Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Tue, 14 May 2024 19:06:59 -0700
Subject: [PATCH 1/5] HLSL Availability Diagnostics Design Document - initial
 commit

---
 clang/docs/HLSL/AvailabilityDiagnostics.rst | 50 +
 clang/docs/HLSL/HLSLDocs.rst|  1 +
 2 files changed, 51 insertions(+)
 create mode 100644 clang/docs/HLSL/AvailabilityDiagnostics.rst

diff --git a/clang/docs/HLSL/AvailabilityDiagnostics.rst 
b/clang/docs/HLSL/AvailabilityDiagnostics.rst
new file mode 100644
index 0..218047495e6b9
--- /dev/null
+++ b/clang/docs/HLSL/AvailabilityDiagnostics.rst
@@ -0,0 +1,50 @@
+=
+HLSL Availability Diagnostics
+=
+
+.. contents::
+   :local:
+
+Introduction
+
+
+HLSL availability diagnostics emits errors or warning when unavailable shader 
APIs are used. Unavailable shader APIs are APIs that are exposed in HLSL code 
but are not available in the target shader stage or shader model version.
+
+There are three modes of HLSL availability diagnostic:
+1. **Default mode** - compiler emits an error when an unavailable shader API 
is found in a code that is reachable from the shader entry point function or 
from an exported library function (when compiling a shader library)
+2. **Relaxed mode** - same as default mode except the compiler emits a 
warning. This mode is enabled by ``-Wno-error=hlsl-availability``.
+3. **Strict mode** - compiler emits an error when when an unavailable API is 
found in parsed code regardless of whether it can be reached from the shader 
entry point or exported functions, or not. This mode is enabled by 
``-fhlsl-strict-diagnostics``.
+
+Implementation Details
+==
+
+Environment Parameter
+-
+
+In order to encode API availability based on the shader model version and 
shader model stage a new ``environment`` parameter was added to the existing 
Clang ``availability`` attribute. 
+
+The values allowed for this parameter are a subset of values allowed as the 
``llvm::Triple`` environment component. If the environment parameters is 
present, the declared availability attribute applies only to targets with the 
same platform and environment.
+
+Default and Relaxed Diagnostic Modes
+
+
+This mode is implemeted in ``DiagnoseHLSLAvailability`` class in 
``SemaHLSL.cpp`` and it is invoked after the whole translation unit is parsed 
(from ``Sema::ActOnEndOfTranslationUnit``). The implementation iterates over 
all shader entry points and exported library functions in the translation unit 
and performs an AST traversal of each function body.
+
+When a reference to another function is found and it has a body, the AST of 
the referenced function is also scanned. This chain of AST traversals will 
reach all of the code that is reachable from the initial shader entry point or 
exported library function.
+
+All shader APIs have an availability attribute that specifies the shader model 
version (and environment, if applicable) when this API was first 
introduced.When a reference to a function without a definition is found and it 
has an availability attribute, the version of the attribute is checked against 
the target shader model version and shader stage (if shader stage context is 
known), and an appropriate diagnostic is generated as needed.
+
+All shader entry functions have ``HLSLShaderAttr`` attribute that specifies 
what type of shader this function represents. However, for exported library 
functions the target shader stage is unknown, so in this case the HLSL API 
availability will be only checked against the shader model version.
+
+A list of functions that were already scanned is kept in order to avoid 
duplicate scans and diagnostics (see 
``DiagnoseHLSLAvailability::ScannedDecls``). It might happen that a shader 
library has multiple shader entry points for different shader stages that all 
call into the same shared function. It is therefore important to record not 
just that a function has been scanned, but also in which shader stage context. 
This is done by using ``llvm::DenseMap`` that maps ``FunctionDecl *`` to a 
``unsigned`` bitmap that represents a set of shader stages (or environments) 
the function has been scanned for. The ``N``'th bit in the set is set if the 
function has been scanned in shader environment whose 
``HLSLShaderAttr::ShaderType`` integer value equals ``N``.
+
+The emitted diagnostic messages belong to ``hlsl-availability`` diagnostic 
group and are reported as errors by default. With 
``-Wno-error=hlsl-availability`` flang they become warning, making it relaxed 
HLSL diagnostics mode.
+
+Strict Diagnostic Mode
+--
+
+When strict HLSL availability diagnostic mode is enabled the compiler must 
report all HLSL API availab

[clang] HLSL availability diagnostics design doc (PR #92207)

2024-05-16 Thread Helena Kotas via cfe-commits

https://github.com/hekota edited https://github.com/llvm/llvm-project/pull/92207
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Serialization] Read the initializer for interesting static variables before consuming it (PR #92353)

2024-05-16 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

> I can reproduce the failure. The problem is that the CHECK line
> 
> ```
> // CHECK: [[A_CALL:%[a-zA-Z0-9]+]] = call{{.*}}@_Z6MakeVR(
> ```
> 
> assumes that a value is returned. On SystemZ, the return value is passed as 
> `sret` argument, and the function itself returns `void`, so the pattern does 
> not match.

Oh, thanks! I never heard that before. I guess I don't need to check the call 
since what I need to check is the order the variable get initialized.

I'll try to land this after the build bot gets green.

https://github.com/llvm/llvm-project/pull/92353
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [X86] Support EGPR for inline assembly. (PR #92338)

2024-05-16 Thread Freddy Ye via cfe-commits

https://github.com/FreddyLeaf updated 
https://github.com/llvm/llvm-project/pull/92338

>From 41fbc18c7a4a26b11bc4b772bbe2e384ad9d9dbc Mon Sep 17 00:00:00 2001
From: Freddy Ye 
Date: Fri, 10 May 2024 16:29:55 +0800
Subject: [PATCH 1/4] [X86] Support EGPR for inline assembly.

"jR": explictly enables EGPR
"r": enables/disables EGPR w/wo -mapx-inline-asm-use-gpr32
-mapx-inline-asm-use-gpr32 will also define a new Macro:
__APX_INLINE_ASM_USE_GPR32__
---
 clang/include/clang/Driver/Options.td |  2 +
 clang/lib/Basic/Targets/X86.cpp   | 26 +
 clang/lib/Basic/Targets/X86.h |  1 +
 clang/lib/Driver/ToolChains/Arch/X86.cpp  |  2 +
 .../Driver/x86-apx-inline-asm-use-gpr32.cpp   |  3 +
 clang/test/Preprocessor/x86_target_features.c |  3 +
 llvm/lib/Target/X86/X86.td|  3 +
 llvm/lib/Target/X86/X86ISelLowering.cpp   | 57 +--
 .../CodeGen/X86/inline-asm-jR-constraint.ll   | 19 +++
 .../CodeGen/X86/inline-asm-r-constraint.ll| 16 ++
 10 files changed, 127 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/Driver/x86-apx-inline-asm-use-gpr32.cpp
 create mode 100644 llvm/test/CodeGen/X86/inline-asm-jR-constraint.ll
 create mode 100644 llvm/test/CodeGen/X86/inline-asm-r-constraint.ll

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 73a2518480e9b..20a7c482bbf06 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -6281,6 +6281,8 @@ def mno_apx_features_EQ : CommaJoined<["-"], 
"mno-apx-features=">, Group, Alias, 
AliasArgs<["egpr","push2pop2","ppx", "ndd"]>;
 def mno_apxf : Flag<["-"], "mno-apxf">, Alias, 
AliasArgs<["egpr","push2pop2","ppx","ndd"]>;
+def mapx_inline_asm_use_gpr32 : Flag<["-"], "mapx-inline-asm-use-gpr32">, 
Group,
+HelpText<"Enable use of GPR32 in inline 
assembly for APX">;
 } // let Flags = [TargetSpecific]
 
 // VE feature flags
diff --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp
index 67e2126cf766b..9e61b6e6d6441 100644
--- a/clang/lib/Basic/Targets/X86.cpp
+++ b/clang/lib/Basic/Targets/X86.cpp
@@ -450,6 +450,8 @@ bool 
X86TargetInfo::handleTargetFeatures(std::vector &Features,
   HasFullBFloat16 = true;
 } else if (Feature == "+egpr") {
   HasEGPR = true;
+} else if (Feature == "+inline-asm-use-gpr32") {
+  HasInlineAsmUseGPR32 = true;
 } else if (Feature == "+push2pop2") {
   HasPush2Pop2 = true;
 } else if (Feature == "+ppx") {
@@ -974,6 +976,8 @@ void X86TargetInfo::getTargetDefines(const LangOptions 
&Opts,
   // Condition here is aligned with the feature set of mapxf in Options.td
   if (HasEGPR && HasPush2Pop2 && HasPPX && HasNDD)
 Builder.defineMacro("__APX_F__");
+  if (HasInlineAsmUseGPR32)
+Builder.defineMacro("__APX_INLINE_ASM_USE_GPR32__");
 
   // Each case falls through to the previous one here.
   switch (SSELevel) {
@@ -1493,6 +1497,15 @@ bool X86TargetInfo::validateAsmConstraint(
   case 'C': // SSE floating point constant.
   case 'G': // x87 floating point constant.
 return true;
+  case 'j':
+Name++;
+switch (*Name) {
+default:
+  return false;
+case 'R':
+  Info.setAllowsRegister();
+  return true;
+}
   case '@':
 // CC condition changes.
 if (auto Len = matchAsmCCConstraint(Name)) {
@@ -1764,6 +1777,19 @@ std::string X86TargetInfo::convertConstraint(const char 
*&Constraint) const {
   // to the next constraint.
   return std::string("^") + std::string(Constraint++, 2);
 }
+  case 'j':
+switch (Constraint[1]) {
+default:
+  // Break from inner switch and fall through (copy single char),
+  // continue parsing after copying the current constraint into
+  // the return string.
+  break;
+case 'R':
+  // "^" hints llvm that this is a 2 letter constraint.
+  // "Constraint++" is used to promote the string iterator
+  // to the next constraint.
+  return std::string("^") + std::string(Constraint++, 2);
+}
 [[fallthrough]];
   default:
 return std::string(1, *Constraint);
diff --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h
index c14e4d5f433d8..69c68ee80f3ba 100644
--- a/clang/lib/Basic/Targets/X86.h
+++ b/clang/lib/Basic/Targets/X86.h
@@ -174,6 +174,7 @@ class LLVM_LIBRARY_VISIBILITY X86TargetInfo : public 
TargetInfo {
   bool HasNDD = false;
   bool HasCCMP = false;
   bool HasCF = false;
+  bool HasInlineAsmUseGPR32 = false;
 
 protected:
   llvm::X86::CPUKind CPU = llvm::X86::CK_None;
diff --git a/clang/lib/Driver/ToolChains/Arch/X86.cpp 
b/clang/lib/Driver/ToolChains/Arch/X86.cpp
index 53e26a9f8e229..085ff4824a9b0 100644
--- a/clang/lib/Driver/ToolChains/Arch/X86.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/X86.cpp
@@ -309,4 +309,6 @@ void x86::getX86TargetFeatures(const Driver &D, const 
llvm::Triple &Triple,
 Features.push_back("+prefer-no-gathe

[clang] [clang-cl][AST] Fix auto NTTP MSVC 1920+ mangling for pointer types (PR #92477)

2024-05-16 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Max Winkler (MaxEW707)


Changes

https://godbolt.org/z/G1K8Wszn9 for reference.

Starting with MSVC 1920+, VS2019, C++17 auto NTTP now adds `M ` to 
the mangled name to avoid name collisions with different deduced types.
This PR fixes pointers. Pointers to members will be fixed in an upcoming PR.

Here is a small example. The godbolt has more thorough examples.
```
template
struct AutoParmTemplate
{
AutoParmTemplate() {}
};

int i;

int main()
{
// MSVC 1916: ??0?$AutoParmTemplate@$1?i@@3HA@@QEAA@XZ
// MSVC 1929: ??0?$AutoParmTemplate@$MPEAH1?i@@3HA@@QEAA@XZ
// Clang : ??0?$AutoParmTemplate@$1?i@@3HA@@QEAA@XZ
AutoParmTemplate<&i> x;
}
```

---
Full diff: https://github.com/llvm/llvm-project/pull/92477.diff


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+7) 
- (modified) clang/lib/AST/MicrosoftMangle.cpp (+60-3) 
- (modified) clang/test/CodeGenCXX/mangle-ms-auto-templates.cpp (+31) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index a3c8e4141ca54..80ea74ed295f9 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -79,6 +79,13 @@ ABI Changes in This Version
 - Fixed Microsoft calling convention when returning classes that have a deleted
   copy assignment operator. Such a class should be returned indirectly.
 
+- Fixed Microsoft name mangling for auto non-type template arguments of pointer
+  type for MSVC 1920+. This change resolves incompatibilities with code 
compiled
+  by MSVC 1920+ but will introduce incompatibilities with code compiled by
+  earlier versions of Clang unless such code is built with the compiler option
+  `-fms-compatibility-version=19.14` to imitate the MSVC 1914 mangling 
behavior.
+
+
 AST Dumping Potentially Breaking Changes
 
 
diff --git a/clang/lib/AST/MicrosoftMangle.cpp 
b/clang/lib/AST/MicrosoftMangle.cpp
index 36d611750ca48..627c4511f2816 100644
--- a/clang/lib/AST/MicrosoftMangle.cpp
+++ b/clang/lib/AST/MicrosoftMangle.cpp
@@ -372,6 +372,11 @@ class MicrosoftCXXNameMangler {
   void mangleMemberFunctionPointer(const CXXRecordDecl *RD,
const CXXMethodDecl *MD,
StringRef Prefix = "$");
+  void mangleFunctionPointer(const FunctionDecl *FD,
+ const NonTypeTemplateParmDecl *PD,
+ QualType TemplateArgType);
+  void mangleVarDecl(const VarDecl *VD, const NonTypeTemplateParmDecl *PD,
+ QualType TemplateArgType);
   void mangleMemberFunctionPointerInClassNTTP(const CXXRecordDecl *RD,
   const CXXMethodDecl *MD);
   void mangleVirtualMemPtrThunk(const CXXMethodDecl *MD,
@@ -799,6 +804,50 @@ MicrosoftCXXNameMangler::mangleMemberFunctionPointer(const 
CXXRecordDecl *RD,
 mangleNumber(VBTableOffset);
 }
 
+void MicrosoftCXXNameMangler::mangleFunctionPointer(
+const FunctionDecl *FD, const NonTypeTemplateParmDecl *PD,
+QualType TemplateArgType) {
+  //  ::= $1? 
+  //  ::= 
+  //
+  //  ::= $ M  1? 
+  Out << '$';
+
+  if (getASTContext().getLangOpts().isCompatibleWithMSVC(
+  LangOptions::MSVC2019) &&
+  PD && PD->getType()->getTypeClass() == Type::Auto &&
+  !TemplateArgType.isNull()) {
+Out << "M";
+mangleType(TemplateArgType, SourceRange(), QMM_Drop);
+  }
+
+  Out << "1?";
+  mangleName(FD);
+  mangleFunctionEncoding(FD, /*ShouldMangle=*/true);
+}
+
+void MicrosoftCXXNameMangler::mangleVarDecl(const VarDecl *VD,
+const NonTypeTemplateParmDecl *PD,
+QualType TemplateArgType) {
+  //  ::= $1? 
+  //  ::= 
+  //
+  //  ::= $ M  1? 
+  Out << '$';
+
+  if (getASTContext().getLangOpts().isCompatibleWithMSVC(
+  LangOptions::MSVC2019) &&
+  PD && PD->getType()->getTypeClass() == Type::Auto &&
+  !TemplateArgType.isNull()) {
+Out << "M";
+mangleType(TemplateArgType, SourceRange(), QMM_Drop);
+  }
+
+  Out << "1?";
+  mangleName(VD);
+  mangleVariableEncoding(VD);
+}
+
 void MicrosoftCXXNameMangler::mangleMemberFunctionPointerInClassNTTP(
 const CXXRecordDecl *RD, const CXXMethodDecl *MD) {
   //  ::= 
@@ -1552,6 +1601,9 @@ void MicrosoftCXXNameMangler::mangleIntegerLiteral(
 const llvm::APSInt &Value, const NonTypeTemplateParmDecl *PD,
 QualType TemplateArgType) {
   //  ::= $0 
+  //  ::= 
+  //
+  //  ::= $ M  0 
   Out << "$";
 
   // Since MSVC 2019, add 'M[]' after '$' for auto template parameter 
when
@@ -1629,8 +1681,11 @@ void MicrosoftCXXNameMangler::mangleTemplateArg(const 
TemplateDecl *TD,
   //::= 
   //::= 
   //::= $ 
+  //::= $ 
   //::= 
   //
+  //  ::= M  
+  //
   //  ::= 0# integer
   //  ::= 1

[clang] [clang-cl][AST] Fix auto NTTP MSVC 1920+ mangling for pointer types (PR #92477)

2024-05-16 Thread Max Winkler via cfe-commits

https://github.com/MaxEW707 created 
https://github.com/llvm/llvm-project/pull/92477

https://godbolt.org/z/G1K8Wszn9 for reference.

Starting with MSVC 1920+, VS2019, C++17 auto NTTP now adds `M ` to the 
mangled name to avoid name collisions with different deduced types.
This PR fixes pointers. Pointers to members will be fixed in an upcoming PR.

Here is a small example. The godbolt has more thorough examples.
```
template
struct AutoParmTemplate
{
AutoParmTemplate() {}
};

int i;

int main()
{
// MSVC 1916: ??0?$AutoParmTemplate@$1?i@@3HA@@QEAA@XZ
// MSVC 1929: ??0?$AutoParmTemplate@$MPEAH1?i@@3HA@@QEAA@XZ
// Clang : ??0?$AutoParmTemplate@$1?i@@3HA@@QEAA@XZ
AutoParmTemplate<&i> x;
}
```

>From 7b73c2b907b09ec87197e9613c4abc27ff52083b Mon Sep 17 00:00:00 2001
From: MaxEW707 
Date: Thu, 16 May 2024 21:03:46 -0400
Subject: [PATCH] [clang-cl][AST] Fix auto NTTP MSVC 1920+ mangling

---
 clang/docs/ReleaseNotes.rst   |  7 +++
 clang/lib/AST/MicrosoftMangle.cpp | 63 ++-
 .../CodeGenCXX/mangle-ms-auto-templates.cpp   | 31 +
 3 files changed, 98 insertions(+), 3 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index a3c8e4141ca54..80ea74ed295f9 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -79,6 +79,13 @@ ABI Changes in This Version
 - Fixed Microsoft calling convention when returning classes that have a deleted
   copy assignment operator. Such a class should be returned indirectly.
 
+- Fixed Microsoft name mangling for auto non-type template arguments of pointer
+  type for MSVC 1920+. This change resolves incompatibilities with code 
compiled
+  by MSVC 1920+ but will introduce incompatibilities with code compiled by
+  earlier versions of Clang unless such code is built with the compiler option
+  `-fms-compatibility-version=19.14` to imitate the MSVC 1914 mangling 
behavior.
+
+
 AST Dumping Potentially Breaking Changes
 
 
diff --git a/clang/lib/AST/MicrosoftMangle.cpp 
b/clang/lib/AST/MicrosoftMangle.cpp
index 36d611750ca48..627c4511f2816 100644
--- a/clang/lib/AST/MicrosoftMangle.cpp
+++ b/clang/lib/AST/MicrosoftMangle.cpp
@@ -372,6 +372,11 @@ class MicrosoftCXXNameMangler {
   void mangleMemberFunctionPointer(const CXXRecordDecl *RD,
const CXXMethodDecl *MD,
StringRef Prefix = "$");
+  void mangleFunctionPointer(const FunctionDecl *FD,
+ const NonTypeTemplateParmDecl *PD,
+ QualType TemplateArgType);
+  void mangleVarDecl(const VarDecl *VD, const NonTypeTemplateParmDecl *PD,
+ QualType TemplateArgType);
   void mangleMemberFunctionPointerInClassNTTP(const CXXRecordDecl *RD,
   const CXXMethodDecl *MD);
   void mangleVirtualMemPtrThunk(const CXXMethodDecl *MD,
@@ -799,6 +804,50 @@ MicrosoftCXXNameMangler::mangleMemberFunctionPointer(const 
CXXRecordDecl *RD,
 mangleNumber(VBTableOffset);
 }
 
+void MicrosoftCXXNameMangler::mangleFunctionPointer(
+const FunctionDecl *FD, const NonTypeTemplateParmDecl *PD,
+QualType TemplateArgType) {
+  //  ::= $1? 
+  //  ::= 
+  //
+  //  ::= $ M  1? 
+  Out << '$';
+
+  if (getASTContext().getLangOpts().isCompatibleWithMSVC(
+  LangOptions::MSVC2019) &&
+  PD && PD->getType()->getTypeClass() == Type::Auto &&
+  !TemplateArgType.isNull()) {
+Out << "M";
+mangleType(TemplateArgType, SourceRange(), QMM_Drop);
+  }
+
+  Out << "1?";
+  mangleName(FD);
+  mangleFunctionEncoding(FD, /*ShouldMangle=*/true);
+}
+
+void MicrosoftCXXNameMangler::mangleVarDecl(const VarDecl *VD,
+const NonTypeTemplateParmDecl *PD,
+QualType TemplateArgType) {
+  //  ::= $1? 
+  //  ::= 
+  //
+  //  ::= $ M  1? 
+  Out << '$';
+
+  if (getASTContext().getLangOpts().isCompatibleWithMSVC(
+  LangOptions::MSVC2019) &&
+  PD && PD->getType()->getTypeClass() == Type::Auto &&
+  !TemplateArgType.isNull()) {
+Out << "M";
+mangleType(TemplateArgType, SourceRange(), QMM_Drop);
+  }
+
+  Out << "1?";
+  mangleName(VD);
+  mangleVariableEncoding(VD);
+}
+
 void MicrosoftCXXNameMangler::mangleMemberFunctionPointerInClassNTTP(
 const CXXRecordDecl *RD, const CXXMethodDecl *MD) {
   //  ::= 
@@ -1552,6 +1601,9 @@ void MicrosoftCXXNameMangler::mangleIntegerLiteral(
 const llvm::APSInt &Value, const NonTypeTemplateParmDecl *PD,
 QualType TemplateArgType) {
   //  ::= $0 
+  //  ::= 
+  //
+  //  ::= $ M  0 
   Out << "$";
 
   // Since MSVC 2019, add 'M[]' after '$' for auto template parameter 
when
@@ -1629,8 +1681,11 @@ void MicrosoftCXXNameMangler::mangleTemplateArg(const 
TemplateDecl *TD,
   //::= 
   //::= 
   //::= $ 
+  // 

[clang] [CodeGen] Support arrays with initializers of 64-bit size (PR #92473)

2024-05-16 Thread Eli Friedman via cfe-commits


@@ -949,11 +949,11 @@ tryEmitGlobalCompoundLiteral(ConstantEmitter &emitter,
 
 static llvm::Constant *
 EmitArrayConstant(CodeGenModule &CGM, llvm::ArrayType *DesiredType,
-  llvm::Type *CommonElementType, unsigned ArrayBound,
+  llvm::Type *CommonElementType, uint64_t ArrayBound,
   SmallVectorImpl &Elements,
   llvm::Constant *Filler) {
   // Figure out how long the initial prefix of non-zero elements is.
-  unsigned NonzeroLength = ArrayBound;
+  uint64_t NonzeroLength = ArrayBound;
   if (Elements.size() < NonzeroLength && Filler->isNullValue())
 NonzeroLength = Elements.size();
   if (NonzeroLength == Elements.size()) {

efriedma-quic wrote:

Do we also need to fix the type of `TrailingZeroes`?

https://github.com/llvm/llvm-project/pull/92473
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [IR] Add getelementptr nusw and nuw flags (PR #90824)

2024-05-16 Thread Nikita Popov via cfe-commits


@@ -0,0 +1,93 @@
+//===-- llvm/GEPNoWrapFlags.h - NoWrap flags for GEPs ---*- 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 defines the nowrap flags for getelementptr operators.
+//
+//===--===//
+
+#ifndef LLVM_IR_GEPNOWRAPFLAGS_H
+#define LLVM_IR_GEPNOWRAPFLAGS_H
+
+namespace llvm {
+
+/// Represents flags for the getelementptr instruction/expression.
+/// The following flags are supported:
+///  * inbounds (implies nusw)
+///  * nusw (no unsigned signed wrap)
+///  * nuw (no unsigned wrap)
+/// See LangRef for a description of their semantics.
+class GEPNoWrapFlags {
+  enum : unsigned {
+InBoundsFlag = (1 << 0),
+NUSWFlag = (1 << 1),
+NUWFlag = (1 << 2),
+  };
+
+  unsigned Flags;
+  GEPNoWrapFlags(unsigned Flags) : Flags(Flags) {
+assert((!isInBounds() || hasNoUnsignedSignedWrap()) &&
+   "inbounds implies nusw");
+  }
+
+public:
+  GEPNoWrapFlags() : Flags(0) {}
+  // For historical reasons, interpret plain boolean as InBounds.
+  // TODO: Migrate users to pass explicit GEPNoWrapFlags and remove this ctor.
+  GEPNoWrapFlags(bool IsInBounds)

nikic wrote:

This is a backwards-compatiblity ctor because we're replacing existing `bool 
IsInBounds` parameters with `GEPNoWrapFlags NW` instead. As the TODO indicates, 
this ctor will be removed in the future. It avoids having to touch large 
amounts of code in this PR in sub-optimal ways.

https://github.com/llvm/llvm-project/pull/90824
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] CTAD alias: Emit a more descriptive diagnostic message when is_deducible constraint is evaluated to false. (PR #92389)

2024-05-16 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

I already fixed this. We just had to constrain the triple, as there are 
differences in size_t underlying type which affect diagnostics.

https://github.com/llvm/llvm-project/pull/92389
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Implement provisional wording for CWG2398 regarding packs (PR #90820)

2024-05-16 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

I just double checked, the issue is present on main before this PR was merged, 
it's completely unrelated.

https://github.com/llvm/llvm-project/pull/90820
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] CTAD alias: Emit a more descriptive diagnostic message when is_deducible constraint is evaluated to false. (PR #92389)

2024-05-16 Thread via cfe-commits

zeroomega wrote:

Hi @hokein , your change probably broke the test "Clang :: 
SemaCXX/cxx20-ctad-type-alias.cpp" on Windows. Could you take a look please?

We are seeing test failures on this with error message:

```
Exit Code: 1

Command Output (stdout):
--
# RUN: at line 1
c:\b\s\w\ir\x\w\llvm_build\bin\clang.exe -cc1 -internal-isystem 
C:\b\s\w\ir\x\w\llvm_build\lib\clang\19\include -nostdsysteminc -fsyntax-only 
-Wno-c++11-narrowing -Wno-literal-conversion -std=c++20 -verify 
C:\b\s\w\ir\x\w\llvm-llvm-project\clang\test\SemaCXX\cxx20-ctad-type-alias.cpp
# executed command: 'c:\b\s\w\ir\x\w\llvm_build\bin\clang.exe' -cc1 
-internal-isystem 'C:\b\s\w\ir\x\w\llvm_build\lib\clang\19\include' 
-nostdsysteminc -fsyntax-only -Wno-c++11-narrowing -Wno-literal-conversion 
-std=c++20 -verify 
'C:\b\s\w\ir\x\w\llvm-llvm-project\clang\test\SemaCXX\cxx20-ctad-type-alias.cpp'
# .---command stderr
# | error: 'expected-note' diagnostics expected but not seen: 
# |   File 
C:\b\s\w\ir\x\w\llvm-llvm-project\clang\test\SemaCXX\cxx20-ctad-type-alias.cpp 
Line 112: cannot deduce template arguments for 'Bar' from 'Foo'
# | error: 'expected-note' diagnostics seen but not expected: 
# |   File 
C:\b\s\w\ir\x\w\llvm-llvm-project\clang\test\SemaCXX\cxx20-ctad-type-alias.cpp 
Line 112: cannot deduce template arguments for 'Bar' from 'Foo'
# | 2 errors generated.
# `-
# error: command failed with exit status: 1

--
```

This happens on our Windows builder. Link to the task: 
https://ci.chromium.org/ui/p/fuchsia/builders/toolchain.ci/clang-windows-x64/b8747755569988931969/overview

https://github.com/llvm/llvm-project/pull/92389
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Sema] Fix last argument not being used when comparing function template specializations when one has an explicit object argument (PR #92263)

2024-05-16 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov approved this pull request.

LGTM, thanks for the fix!

https://github.com/llvm/llvm-project/pull/92263
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][CodeGen] Remove unused LValue::getAddress CGF arg. (PR #92465)

2024-05-16 Thread Akira Hatanaka via cfe-commits

https://github.com/ahatanak approved this pull request.


https://github.com/llvm/llvm-project/pull/92465
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [CodeGen] Support arrays with initializers of 64-bit size (PR #92473)

2024-05-16 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Fangrui Song (MaskRay)


Changes

Based on @OfekShochat's https://reviews.llvm.org/D133648

init.c is the primary test for array initialization, but it uses a
32-bit triple, which would lead to an "array is too large" error. Add
the new test to array-init.c instead.

Fix #57353


---
Full diff: https://github.com/llvm/llvm-project/pull/92473.diff


3 Files Affected:

- (modified) clang/lib/CodeGen/CGExprConstant.cpp (+6-6) 
- (modified) clang/lib/Sema/SemaInit.cpp (+2-2) 
- (modified) clang/test/CodeGen/array-init.c (+7) 


``diff
diff --git a/clang/lib/CodeGen/CGExprConstant.cpp 
b/clang/lib/CodeGen/CGExprConstant.cpp
index 94962091116af..ce57279a6eb65 100644
--- a/clang/lib/CodeGen/CGExprConstant.cpp
+++ b/clang/lib/CodeGen/CGExprConstant.cpp
@@ -393,7 +393,7 @@ bool ConstantAggregateBuilder::split(size_t Index, 
CharUnits Hint) {
 
 static llvm::Constant *
 EmitArrayConstant(CodeGenModule &CGM, llvm::ArrayType *DesiredType,
-  llvm::Type *CommonElementType, unsigned ArrayBound,
+  llvm::Type *CommonElementType, uint64_t ArrayBound,
   SmallVectorImpl &Elements,
   llvm::Constant *Filler);
 
@@ -949,11 +949,11 @@ tryEmitGlobalCompoundLiteral(ConstantEmitter &emitter,
 
 static llvm::Constant *
 EmitArrayConstant(CodeGenModule &CGM, llvm::ArrayType *DesiredType,
-  llvm::Type *CommonElementType, unsigned ArrayBound,
+  llvm::Type *CommonElementType, uint64_t ArrayBound,
   SmallVectorImpl &Elements,
   llvm::Constant *Filler) {
   // Figure out how long the initial prefix of non-zero elements is.
-  unsigned NonzeroLength = ArrayBound;
+  uint64_t NonzeroLength = ArrayBound;
   if (Elements.size() < NonzeroLength && Filler->isNullValue())
 NonzeroLength = Elements.size();
   if (NonzeroLength == Elements.size()) {
@@ -1252,12 +1252,12 @@ class ConstExprEmitter
   llvm::Constant *EmitArrayInitialization(const InitListExpr *ILE, QualType T) 
{
 auto *CAT = CGM.getContext().getAsConstantArrayType(ILE->getType());
 assert(CAT && "can't emit array init for non-constant-bound array");
-unsigned NumInitElements = ILE->getNumInits();
-unsigned NumElements = CAT->getZExtSize();
+const uint64_t NumElements = CAT->getZExtSize();
 
 // Initialising an array requires us to automatically
 // initialise any elements that have not been initialised explicitly
-unsigned NumInitableElts = std::min(NumInitElements, NumElements);
+uint64_t NumInitableElts =
+std::min(ILE->getNumInits(), NumElements);
 
 QualType EltType = CAT->getElementType();
 
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 2177972f3af2c..353e911c5cc33 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -876,7 +876,7 @@ InitListChecker::FillInEmptyInitializations(const 
InitializedEntity &Entity,
 
   InitializedEntity ElementEntity = Entity;
   unsigned NumInits = ILE->getNumInits();
-  unsigned NumElements = NumInits;
+  uint64_t NumElements = NumInits;
   if (const ArrayType *AType = SemaRef.Context.getAsArrayType(ILE->getType())) 
{
 ElementType = AType->getElementType();
 if (const auto *CAType = dyn_cast(AType))
@@ -896,7 +896,7 @@ InitListChecker::FillInEmptyInitializations(const 
InitializedEntity &Entity,
 ElementType = ILE->getType();
 
   bool SkipEmptyInitChecks = false;
-  for (unsigned Init = 0; Init != NumElements; ++Init) {
+  for (uint64_t Init = 0; Init != NumElements; ++Init) {
 if (hadError)
   return;
 
diff --git a/clang/test/CodeGen/array-init.c b/clang/test/CodeGen/array-init.c
index 62e87edc29741..9075df68c7358 100644
--- a/clang/test/CodeGen/array-init.c
+++ b/clang/test/CodeGen/array-init.c
@@ -13,3 +13,10 @@ void testConstArrayInits(void)
   const int a2[5] = {0,0,0};
   const int a3[5] = {0};
 }
+
+/// https://github.com/llvm/llvm-project/issues/57353
+// CHECK: @big_char ={{.*}} global <{ i8, [4294967295 x i8] }> <{ i8 1, 
[4294967295 x i8] zeroinitializer }>
+char big_char[4294967296] = {1};
+
+// CHECK: @big_int ={{.*}} global <{ i32, [2147483647 x i32] }> <{ i32 1, 
[2147483647 x i32] zeroinitializer }>
+int big_int[0x2 >> 2] = {1};

``




https://github.com/llvm/llvm-project/pull/92473
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [CodeGen] Support arrays with initializers of 64-bit size (PR #92473)

2024-05-16 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Fangrui Song (MaskRay)


Changes

Based on @OfekShochat's https://reviews.llvm.org/D133648

init.c is the primary test for array initialization, but it uses a
32-bit triple, which would lead to an "array is too large" error. Add
the new test to array-init.c instead.

Fix #57353


---
Full diff: https://github.com/llvm/llvm-project/pull/92473.diff


3 Files Affected:

- (modified) clang/lib/CodeGen/CGExprConstant.cpp (+6-6) 
- (modified) clang/lib/Sema/SemaInit.cpp (+2-2) 
- (modified) clang/test/CodeGen/array-init.c (+7) 


``diff
diff --git a/clang/lib/CodeGen/CGExprConstant.cpp 
b/clang/lib/CodeGen/CGExprConstant.cpp
index 94962091116af..ce57279a6eb65 100644
--- a/clang/lib/CodeGen/CGExprConstant.cpp
+++ b/clang/lib/CodeGen/CGExprConstant.cpp
@@ -393,7 +393,7 @@ bool ConstantAggregateBuilder::split(size_t Index, 
CharUnits Hint) {
 
 static llvm::Constant *
 EmitArrayConstant(CodeGenModule &CGM, llvm::ArrayType *DesiredType,
-  llvm::Type *CommonElementType, unsigned ArrayBound,
+  llvm::Type *CommonElementType, uint64_t ArrayBound,
   SmallVectorImpl &Elements,
   llvm::Constant *Filler);
 
@@ -949,11 +949,11 @@ tryEmitGlobalCompoundLiteral(ConstantEmitter &emitter,
 
 static llvm::Constant *
 EmitArrayConstant(CodeGenModule &CGM, llvm::ArrayType *DesiredType,
-  llvm::Type *CommonElementType, unsigned ArrayBound,
+  llvm::Type *CommonElementType, uint64_t ArrayBound,
   SmallVectorImpl &Elements,
   llvm::Constant *Filler) {
   // Figure out how long the initial prefix of non-zero elements is.
-  unsigned NonzeroLength = ArrayBound;
+  uint64_t NonzeroLength = ArrayBound;
   if (Elements.size() < NonzeroLength && Filler->isNullValue())
 NonzeroLength = Elements.size();
   if (NonzeroLength == Elements.size()) {
@@ -1252,12 +1252,12 @@ class ConstExprEmitter
   llvm::Constant *EmitArrayInitialization(const InitListExpr *ILE, QualType T) 
{
 auto *CAT = CGM.getContext().getAsConstantArrayType(ILE->getType());
 assert(CAT && "can't emit array init for non-constant-bound array");
-unsigned NumInitElements = ILE->getNumInits();
-unsigned NumElements = CAT->getZExtSize();
+const uint64_t NumElements = CAT->getZExtSize();
 
 // Initialising an array requires us to automatically
 // initialise any elements that have not been initialised explicitly
-unsigned NumInitableElts = std::min(NumInitElements, NumElements);
+uint64_t NumInitableElts =
+std::min(ILE->getNumInits(), NumElements);
 
 QualType EltType = CAT->getElementType();
 
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 2177972f3af2c..353e911c5cc33 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -876,7 +876,7 @@ InitListChecker::FillInEmptyInitializations(const 
InitializedEntity &Entity,
 
   InitializedEntity ElementEntity = Entity;
   unsigned NumInits = ILE->getNumInits();
-  unsigned NumElements = NumInits;
+  uint64_t NumElements = NumInits;
   if (const ArrayType *AType = SemaRef.Context.getAsArrayType(ILE->getType())) 
{
 ElementType = AType->getElementType();
 if (const auto *CAType = dyn_cast(AType))
@@ -896,7 +896,7 @@ InitListChecker::FillInEmptyInitializations(const 
InitializedEntity &Entity,
 ElementType = ILE->getType();
 
   bool SkipEmptyInitChecks = false;
-  for (unsigned Init = 0; Init != NumElements; ++Init) {
+  for (uint64_t Init = 0; Init != NumElements; ++Init) {
 if (hadError)
   return;
 
diff --git a/clang/test/CodeGen/array-init.c b/clang/test/CodeGen/array-init.c
index 62e87edc29741..9075df68c7358 100644
--- a/clang/test/CodeGen/array-init.c
+++ b/clang/test/CodeGen/array-init.c
@@ -13,3 +13,10 @@ void testConstArrayInits(void)
   const int a2[5] = {0,0,0};
   const int a3[5] = {0};
 }
+
+/// https://github.com/llvm/llvm-project/issues/57353
+// CHECK: @big_char ={{.*}} global <{ i8, [4294967295 x i8] }> <{ i8 1, 
[4294967295 x i8] zeroinitializer }>
+char big_char[4294967296] = {1};
+
+// CHECK: @big_int ={{.*}} global <{ i32, [2147483647 x i32] }> <{ i32 1, 
[2147483647 x i32] zeroinitializer }>
+int big_int[0x2 >> 2] = {1};

``




https://github.com/llvm/llvm-project/pull/92473
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [CodeGen] Support arrays with initializers of 64-bit size (PR #92473)

2024-05-16 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay created 
https://github.com/llvm/llvm-project/pull/92473

Based on @OfekShochat's https://reviews.llvm.org/D133648

init.c is the primary test for array initialization, but it uses a
32-bit triple, which would lead to an "array is too large" error. Add
the new test to array-init.c instead.

Fix #57353


>From fec942ed085d2a4004a6cefcb7fdf20a4b062ca3 Mon Sep 17 00:00:00 2001
From: Fangrui Song 
Date: Thu, 16 May 2024 16:24:01 -0700
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
 =?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.5-bogner
---
 clang/lib/CodeGen/CGExprConstant.cpp | 12 ++--
 clang/lib/Sema/SemaInit.cpp  |  4 ++--
 clang/test/CodeGen/array-init.c  |  7 +++
 3 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/clang/lib/CodeGen/CGExprConstant.cpp 
b/clang/lib/CodeGen/CGExprConstant.cpp
index 94962091116af..ce57279a6eb65 100644
--- a/clang/lib/CodeGen/CGExprConstant.cpp
+++ b/clang/lib/CodeGen/CGExprConstant.cpp
@@ -393,7 +393,7 @@ bool ConstantAggregateBuilder::split(size_t Index, 
CharUnits Hint) {
 
 static llvm::Constant *
 EmitArrayConstant(CodeGenModule &CGM, llvm::ArrayType *DesiredType,
-  llvm::Type *CommonElementType, unsigned ArrayBound,
+  llvm::Type *CommonElementType, uint64_t ArrayBound,
   SmallVectorImpl &Elements,
   llvm::Constant *Filler);
 
@@ -949,11 +949,11 @@ tryEmitGlobalCompoundLiteral(ConstantEmitter &emitter,
 
 static llvm::Constant *
 EmitArrayConstant(CodeGenModule &CGM, llvm::ArrayType *DesiredType,
-  llvm::Type *CommonElementType, unsigned ArrayBound,
+  llvm::Type *CommonElementType, uint64_t ArrayBound,
   SmallVectorImpl &Elements,
   llvm::Constant *Filler) {
   // Figure out how long the initial prefix of non-zero elements is.
-  unsigned NonzeroLength = ArrayBound;
+  uint64_t NonzeroLength = ArrayBound;
   if (Elements.size() < NonzeroLength && Filler->isNullValue())
 NonzeroLength = Elements.size();
   if (NonzeroLength == Elements.size()) {
@@ -1252,12 +1252,12 @@ class ConstExprEmitter
   llvm::Constant *EmitArrayInitialization(const InitListExpr *ILE, QualType T) 
{
 auto *CAT = CGM.getContext().getAsConstantArrayType(ILE->getType());
 assert(CAT && "can't emit array init for non-constant-bound array");
-unsigned NumInitElements = ILE->getNumInits();
-unsigned NumElements = CAT->getZExtSize();
+const uint64_t NumElements = CAT->getZExtSize();
 
 // Initialising an array requires us to automatically
 // initialise any elements that have not been initialised explicitly
-unsigned NumInitableElts = std::min(NumInitElements, NumElements);
+uint64_t NumInitableElts =
+std::min(ILE->getNumInits(), NumElements);
 
 QualType EltType = CAT->getElementType();
 
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 2177972f3af2c..353e911c5cc33 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -876,7 +876,7 @@ InitListChecker::FillInEmptyInitializations(const 
InitializedEntity &Entity,
 
   InitializedEntity ElementEntity = Entity;
   unsigned NumInits = ILE->getNumInits();
-  unsigned NumElements = NumInits;
+  uint64_t NumElements = NumInits;
   if (const ArrayType *AType = SemaRef.Context.getAsArrayType(ILE->getType())) 
{
 ElementType = AType->getElementType();
 if (const auto *CAType = dyn_cast(AType))
@@ -896,7 +896,7 @@ InitListChecker::FillInEmptyInitializations(const 
InitializedEntity &Entity,
 ElementType = ILE->getType();
 
   bool SkipEmptyInitChecks = false;
-  for (unsigned Init = 0; Init != NumElements; ++Init) {
+  for (uint64_t Init = 0; Init != NumElements; ++Init) {
 if (hadError)
   return;
 
diff --git a/clang/test/CodeGen/array-init.c b/clang/test/CodeGen/array-init.c
index 62e87edc29741..9075df68c7358 100644
--- a/clang/test/CodeGen/array-init.c
+++ b/clang/test/CodeGen/array-init.c
@@ -13,3 +13,10 @@ void testConstArrayInits(void)
   const int a2[5] = {0,0,0};
   const int a3[5] = {0};
 }
+
+/// https://github.com/llvm/llvm-project/issues/57353
+// CHECK: @big_char ={{.*}} global <{ i8, [4294967295 x i8] }> <{ i8 1, 
[4294967295 x i8] zeroinitializer }>
+char big_char[4294967296] = {1};
+
+// CHECK: @big_int ={{.*}} global <{ i32, [2147483647 x i32] }> <{ i32 1, 
[2147483647 x i32] zeroinitializer }>
+int big_int[0x2 >> 2] = {1};

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


[clang] [-Wunsafe-buffer-usage] Fix false positives for constant cases (PR #92432)

2024-05-16 Thread via cfe-commits


@@ -420,25 +420,63 @@ AST_MATCHER(ArraySubscriptExpr, isSafeArraySubscript) {
   //already duplicated
   //  - call both from Sema and from here
 
-  const auto *BaseDRE =
-  dyn_cast(Node.getBase()->IgnoreParenImpCasts());
-  if (!BaseDRE)
+  if (const auto *BaseDRE =
+  dyn_cast(Node.getBase()->IgnoreParenImpCasts())) {
+if (!BaseDRE->getDecl())
+  return false;
+if (const auto *CATy = Finder->getASTContext().getAsConstantArrayType(
+BaseDRE->getDecl()->getType())) {
+  if (const auto *IdxLit = dyn_cast(Node.getIdx())) {

jkorous-apple wrote:

True but the block is also trivial and I am not convinced factoring it out as a 
separate function is worth it or leads to better code.

https://github.com/llvm/llvm-project/pull/92432
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [-Wunsafe-buffer-usage] Fix false positives for constant cases (PR #92432)

2024-05-16 Thread via cfe-commits


@@ -420,25 +420,63 @@ AST_MATCHER(ArraySubscriptExpr, isSafeArraySubscript) {
   //already duplicated
   //  - call both from Sema and from here
 
-  const auto *BaseDRE =
-  dyn_cast(Node.getBase()->IgnoreParenImpCasts());
-  if (!BaseDRE)
+  if (const auto *BaseDRE =
+  dyn_cast(Node.getBase()->IgnoreParenImpCasts())) {
+if (!BaseDRE->getDecl())
+  return false;
+if (const auto *CATy = Finder->getASTContext().getAsConstantArrayType(
+BaseDRE->getDecl()->getType())) {
+  if (const auto *IdxLit = dyn_cast(Node.getIdx())) {
+const APInt ArrIdx = IdxLit->getValue();
+// FIXME: ArrIdx.isNegative() we could immediately emit an error as
+// that's a bug
+if (ArrIdx.isNonNegative() &&
+ArrIdx.getLimitedValue() < CATy->getLimitedSize())
+  return true;
+  }
+}
+  }
+
+  if (const auto *BaseSL =
+  dyn_cast(Node.getBase()->IgnoreParenImpCasts())) {
+if (const auto *CATy =
+Finder->getASTContext().getAsConstantArrayType(BaseSL->getType())) 
{
+  if (const auto *IdxLit = dyn_cast(Node.getIdx())) {
+const APInt ArrIdx = IdxLit->getValue();
+// FIXME: ArrIdx.isNegative() we could immediately emit an error as
+// that's a bug
+if (ArrIdx.isNonNegative() &&
+ArrIdx.getLimitedValue() < CATy->getLimitedSize())
+  return true;
+  }
+}
+  }
+
+  return false;
+}
+
+AST_MATCHER(BinaryOperator, isSafePtrArithmetic) {
+  if (Node.getOpcode() != BinaryOperatorKind::BO_Add)
 return false;
-  if (!BaseDRE->getDecl())
+
+  const auto *LHSDRE = dyn_cast(Node.getLHS()->IgnoreImpCasts());
+  if (!LHSDRE)
 return false;
+
   const auto *CATy = Finder->getASTContext().getAsConstantArrayType(
-  BaseDRE->getDecl()->getType());
+  LHSDRE->getDecl()->getType());
   if (!CATy)
 return false;
 
-  if (const auto *IdxLit = dyn_cast(Node.getIdx())) {
-const APInt ArrIdx = IdxLit->getValue();
-// FIXME: ArrIdx.isNegative() we could immediately emit an error as that's 
a
-// bug
-if (ArrIdx.isNonNegative() &&
-ArrIdx.getLimitedValue() < CATy->getLimitedSize())
-  return true;
-  }
+  const auto *RHSIntLit = dyn_cast(Node.getRHS());
+  if (!RHSIntLit)
+return false;
+
+  const APInt BufferOffset = RHSIntLit->getValue();
+
+  if (BufferOffset.isNonNegative() &&

jkorous-apple wrote:

True, this is not covered - just like more complex arithmetic expressions with 
are not yet covered with fixits.
But I'd rather land the incomplete solution that possibly addresses majority of 
false positives in real code now and improve the solution later.

https://github.com/llvm/llvm-project/pull/92432
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Implement provisional wording for CWG2398 regarding packs (PR #90820)

2024-05-16 Thread Mehdi Amini via cfe-commits

joker-eph wrote:

Great, thanks for the quick fix!

https://github.com/llvm/llvm-project/pull/90820
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [C++23] [CLANG] Adding C++23 constexpr math functions: fmin, fmax and frexp. (PR #88978)

2024-05-16 Thread Hubert Tong via cfe-commits


@@ -14574,9 +14574,17 @@ bool FloatExprEvaluator::VisitCallExpr(const CallExpr 
*E) {
   default:
 return false;
 
+  case Builtin::BI__builtin_frexpl:
+// AIX library function `frexpl` has 'long double' type and not
+// PPCDoubleDouble type. To make sure we generate the right value, don't
+// constant evaluate it and instead defer to a libcall.
+if (Info.Ctx.getTargetInfo().getTriple().isPPC() &&
+(&Info.Ctx.getTargetInfo().getLongDoubleFormat() !=
+ &llvm::APFloat::PPCDoubleDouble()))
+  return false;
+LLVM_FALLTHROUGH;
   case Builtin::BI__builtin_frexp:
-  case Builtin::BI__builtin_frexpf:
-  case Builtin::BI__builtin_frexpl: {
+  case Builtin::BI__builtin_frexpf: {

hubert-reinterpretcast wrote:

> I was referring to 
> https://github.com/llvm/llvm-project/blob/main/clang/lib/CodeGen/CGBuiltin.cpp#L3543.

That affects the IR generated by Clang when Clang _does not_ constant-evaluate 
(and was motivated by backend issues).

https://github.com/llvm/llvm-project/pull/88978
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Implement provisional wording for CWG2398 regarding packs (PR #90820)

2024-05-16 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

I just pushed a fix.

https://github.com/llvm/llvm-project/pull/90820
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] fe4d5f0 - [clang] NFC: stray space cleanup

2024-05-16 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2024-05-16T19:56:45-03:00
New Revision: fe4d5f0d0e457a0a7dec2c7dc87996706b30a25e

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

LOG: [clang] NFC: stray space cleanup

Added: 


Modified: 
clang/test/SemaCXX/cxx20-ctad-type-alias.cpp

Removed: 




diff  --git a/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp 
b/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp
index 70e81cd79fd67..285532e3d80dd 100644
--- a/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp
+++ b/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp
@@ -74,7 +74,7 @@ struct Foo {
 template 
 using AF = Foo;
 
-AF b{0}; 
+AF b{0};
 }  // namespace test6
 
 namespace test7 {
@@ -86,8 +86,8 @@ struct Foo {
 template 
 using AF1 = Foo;
 template 
-using AF2 = AF1;  
-AF2 b = 1;  
+using AF2 = AF1;
+AF2 b = 1;
 }  // namespace test7
 
 namespace test8 {
@@ -149,7 +149,7 @@ namespace test12 {
 template
 struct Foo {
   template
-  struct Bar { 
+  struct Bar {
 Bar(K);
   };
 



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


[clang] f210152 - [clang] constrain `SemaCXX/cxx20-ctad-type-alias.cpp` target triple

2024-05-16 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2024-05-16T19:56:45-03:00
New Revision: f210152e5fbcec1c50ff5ccc1f6680ab2c39b46f

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

LOG: [clang] constrain `SemaCXX/cxx20-ctad-type-alias.cpp` target triple

The test expectations are otherwise affected by the underlying type of size_t.

Added: 


Modified: 
clang/test/SemaCXX/cxx20-ctad-type-alias.cpp

Removed: 




diff  --git a/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp 
b/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp
index 21b2b8bff5002..70e81cd79fd67 100644
--- a/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp
+++ b/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -Wno-c++11-narrowing -Wno-literal-conversion 
-std=c++20 -verify %s
+// RUN: %clang_cc1 -fsyntax-only -triple x86_64-unknown-linux 
-Wno-c++11-narrowing -Wno-literal-conversion -std=c++20 -verify %s
 
 namespace test1 {
 template 



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


[clang] [clang] Implement provisional wording for CWG2398 regarding packs (PR #90820)

2024-05-16 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

Yep, I confirm the behavior happens if I add `-triple x86_64-windows-msvc` to 
RUN line.

https://github.com/llvm/llvm-project/pull/90820
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [C++23] [CLANG] Adding C++23 constexpr math functions: fmin, fmax and frexp. (PR #88978)

2024-05-16 Thread Hubert Tong via cfe-commits


@@ -14574,9 +14574,17 @@ bool FloatExprEvaluator::VisitCallExpr(const CallExpr 
*E) {
   default:
 return false;
 
+  case Builtin::BI__builtin_frexpl:
+// AIX library function `frexpl` has 'long double' type and not
+// PPCDoubleDouble type. To make sure we generate the right value, don't
+// constant evaluate it and instead defer to a libcall.
+if (Info.Ctx.getTargetInfo().getTriple().isPPC() &&
+(&Info.Ctx.getTargetInfo().getLongDoubleFormat() !=
+ &llvm::APFloat::PPCDoubleDouble()))
+  return false;
+LLVM_FALLTHROUGH;
   case Builtin::BI__builtin_frexp:
-  case Builtin::BI__builtin_frexpf:
-  case Builtin::BI__builtin_frexpl: {
+  case Builtin::BI__builtin_frexpf: {

hubert-reinterpretcast wrote:

> With this change (special casing frexpl for AIX) the IR produced is: `call { 
> double, i32 } @llvm.frexp.f64.i32(double 1.234500e+02)`
> 
> without this change the IR is: `store double 0.00e+00, ptr %returnValue, 
> align 8`
> 
> This doesn't seem correct to me.

Ignoring considerations around storing to `DummyInt`, the original test code 
was:
```
  returnValue = __builtin_frexpl(0.0L, &DummyInt);
```
I don't know where the `123.45` came from. That the result is zero for an input 
of zero is correct.

https://github.com/llvm/llvm-project/pull/88978
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Implement provisional wording for CWG2398 regarding packs (PR #90820)

2024-05-16 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

Weirdly enough the test passes on my machine, latest MacOS.

Maybe the test is not constrained on target, and this is causing differences 
between machines?

https://github.com/llvm/llvm-project/pull/90820
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Implement provisional wording for CWG2398 regarding packs (PR #90820)

2024-05-16 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

The quick fix would be to change the expectations of the test, I can do it for 
you.

https://github.com/llvm/llvm-project/pull/90820
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Implement provisional wording for CWG2398 regarding packs (PR #90820)

2024-05-16 Thread Mehdi Amini via cfe-commits

joker-eph wrote:

So are we reverting here or do you have quick fix available?

https://github.com/llvm/llvm-project/pull/90820
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] visit constraint of NTTP (PR #91842)

2024-05-16 Thread Qizhi Hu via cfe-commits

jcsxky wrote:

> I don't think this is the right approach. I stepped though the example and 
> the reason we reject is because:
> 
> * We substitute a dependent `AutoType` in for the types of the template 
> parameters when they are initially built.
> * We call `getMoreSpecialized` determine whether the partial specialization 
> is more specialized than the primary.
> * We determine that neither template is at least as specialized as the other 
> via `isAtLeastAsSpecializedAs`.
> * We call `TemplateParameterListsAreEqual` per [[temp.func.order] 
> p6.2.2](http://eel.is/c++draft/temp.func.order#6.2.2) to check for template 
> parameter equivalence, and compare the two template parameters by calling 
> `MatchTemplateParameterKind`.
> * `MatchTemplateParameterKind` calls `ASTContext::getUnconstrainedType` to 
> get the unconstrained type of the template parameters per [[temp.over.link] 
> p6 sentence 2](http://eel.is/c++draft/temp.over.link#6.sentence-2). For the 
> class templates template parameter, it returns the type unchanged (a 
> _**dependent**_ `AutoType`). For the class template partial specializations 
> template parameter, it returns an unconstrained `AutoType` _**that isn't 
> dependent**_.
> * We compare the adjusted types and determine they aren't equal, so we 
> consider neither template to be more specialized than the other.
> 
> So, I think the correct fix is to propagate dependence in 
> `ASTContext::getUnconstrainedType`. I have a branch that implements this 
> [here](https://github.com/sdkrystian/llvm-project/tree/partial-spec-dependent-auto).
>  WDYT @erichkeane @cor3ntin @zyn0217?

This is really a perfect approach and it has addressed the underlying issue. 
And thanks for your explaination! 

https://github.com/llvm/llvm-project/pull/91842
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Safe Buffers] Serialize unsafe_buffer_usage pragmas (PR #92031)

2024-05-16 Thread Ziqing Luo via cfe-commits


@@ -1551,6 +1567,58 @@ bool 
Preprocessor::isPPInSafeBufferOptOutRegion(SourceLocation &StartLoc) {
   return InSafeBufferOptOutRegion;
 }
 
+SmallVector
+Preprocessor::serializeSafeBufferOptOutMap() const {
+  assert(!InSafeBufferOptOutRegion &&
+ "Attempt to serialize safe buffer opt-out regions before file being "
+ "completely preprocessed");
+
+  SmallVector SrcSeq;
+
+  for (const auto &[begin, end] : SafeBufferOptOutMap) {
+SrcSeq.push_back(begin);
+SrcSeq.push_back(end);
+  }
+  // Only `SafeBufferOptOutMap` gets serialized. No need to serialize
+  // `LoadedSafeBufferOptOutMap` because if this TU loads a pch/module, every
+  // pch/module in the pch-chain/module-DAG will be loaded one by one in order.
+  // It means that for each loading pch/module m, it just needs to load m's own
+  // `SafeBufferOptOutMap`.
+  return SrcSeq;
+}
+
+void Preprocessor::setDeserializedSafeBufferOptOutMap(
+const SmallVectorImpl &SourceLocations) {
+  auto It = SourceLocations.begin();
+
+  assert(SourceLocations.size() % 2 == 0 &&
+ "ill-formed SourceLocation sequence");
+  while (It != SourceLocations.end()) {
+SourceLocation begin = *It++;
+SourceLocation end = *It++;
+SourceLocation FileLoc = SourceMgr.getFileLoc(begin);
+FileID FID = SourceMgr.getDecomposedLoc(FileLoc).first;
+
+if (FID.isInvalid()) {
+  // I suppose this should not happen:
+  assert(false && "Attempted to read a safe buffer opt-out region whose "
+  "begin location is associated to an invalid File ID.");
+  break;
+}
+assert(!SourceMgr.isLocalFileID(FID) && "Expected a pch/module file");
+// Here we assume that
+// `SourceMgr.getFileLoc(begin) == SourceMgr.getFileLoc(end)`.
+// Though it may not hold in very rare and strange cases, i.e., a pair of

ziqingluo-90 wrote:

yes, we can emit front-end errors.  See this newly added test: 
https://github.com/llvm/llvm-project/pull/92031/files#diff-697faf822726557e5d62bcf106fc6cb03ff333b30b0a42ec192d93e6e12fd8fa

https://github.com/llvm/llvm-project/pull/92031
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Implement provisional wording for CWG2398 regarding packs (PR #90820)

2024-05-16 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

That test was merged after the last time pre-commit CI was run on this MR.

The change looks like a consequence of my refactoring, we now preserve the type 
sugar from the injected arguments.

https://github.com/llvm/llvm-project/pull/90820
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Safe Buffers] Serialize unsafe_buffer_usage pragmas (PR #92031)

2024-05-16 Thread Ziqing Luo via cfe-commits

https://github.com/ziqingluo-90 updated 
https://github.com/llvm/llvm-project/pull/92031

>From ac5aeb5c3a134d085320fc7fc5cf3f2c8c41a1f1 Mon Sep 17 00:00:00 2001
From: ziqingluo-90 
Date: Mon, 13 May 2024 13:31:21 -0700
Subject: [PATCH 1/3] fix safe buffer opt-out region serialization

---
 clang/include/clang/Lex/Preprocessor.h|  22 +++-
 .../include/clang/Serialization/ASTBitCodes.h |   3 +
 clang/lib/Lex/Preprocessor.cpp| 106 ++
 clang/lib/Serialization/ASTReader.cpp |  11 ++
 clang/lib/Serialization/ASTWriter.cpp |   7 ++
 clang/test/Modules/Inputs/SafeBuffers/base.h  |   9 ++
 .../SafeBuffers/safe_buffers_test.modulemap   |  10 ++
 .../Modules/Inputs/SafeBuffers/test_sub1.h|  20 
 .../Modules/Inputs/SafeBuffers/test_sub2.h|  11 ++
 clang/test/Modules/safe_buffers_optout.cpp|  39 +++
 ...unsafe-buffer-usage-pragma-pch-complex.cpp |  72 
 .../warn-unsafe-buffer-usage-pragma-pch.cpp   |  27 +
 12 files changed, 314 insertions(+), 23 deletions(-)
 create mode 100644 clang/test/Modules/Inputs/SafeBuffers/base.h
 create mode 100644 
clang/test/Modules/Inputs/SafeBuffers/safe_buffers_test.modulemap
 create mode 100644 clang/test/Modules/Inputs/SafeBuffers/test_sub1.h
 create mode 100644 clang/test/Modules/Inputs/SafeBuffers/test_sub2.h
 create mode 100644 clang/test/Modules/safe_buffers_optout.cpp
 create mode 100644 
clang/test/SemaCXX/warn-unsafe-buffer-usage-pragma-pch-complex.cpp
 create mode 100644 clang/test/SemaCXX/warn-unsafe-buffer-usage-pragma-pch.cpp

diff --git a/clang/include/clang/Lex/Preprocessor.h 
b/clang/include/clang/Lex/Preprocessor.h
index e89b4a2c5230e..8d6884ebe7597 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -2883,11 +2883,15 @@ class Preprocessor {
   /// otherwise.
   SourceLocation CurrentSafeBufferOptOutStart; // It is used to report the 
start location of an never-closed region.
 
-  // An ordered sequence of "-Wunsafe-buffer-usage" opt-out regions in one
-  // translation unit. Each region is represented by a pair of start and end
-  // locations.  A region is "open" if its' start and end locations are
+  using SafeBufferOptOutMapTy =
+  SmallVector, 16>;
+  // An ordered sequence of "-Wunsafe-buffer-usage" opt-out regions in this
+  // translation unit. Each region is represented by a pair of start and
+  // end locations.  A region is "open" if its' start and end locations are
   // identical.
-  SmallVector, 8> 
SafeBufferOptOutMap;
+  SafeBufferOptOutMapTy SafeBufferOptOutMap;
+  // `SafeBufferOptOutMap`s of loaded files:
+  llvm::DenseMap LoadedSafeBufferOptOutMap;
 
 public:
   /// \return true iff the given `Loc` is in a "-Wunsafe-buffer-usage" opt-out
@@ -2918,6 +2922,16 @@ class Preprocessor {
   ///  opt-out region
   bool isPPInSafeBufferOptOutRegion(SourceLocation &StartLoc);
 
+  /// \return a sequence of SourceLocations representing ordered opt-out 
regions
+  /// specified by
+  /// `\#pragma clang unsafe_buffer_usage begin/end`s of this translation unit.
+  SmallVector serializeSafeBufferOptOutMap() const;
+
+  /// \param SrcLocSeqs a sequence of SourceLocations deserialized from a
+  /// record of code `PP_UNSAFE_BUFFER_USAGE`.
+  void setDeserializedSafeBufferOptOutMap(
+  const SmallVectorImpl &SrcLocSeqs);
+
 private:
   /// Helper functions to forward lexing to the actual lexer. They all share 
the
   /// same signature.
diff --git a/clang/include/clang/Serialization/ASTBitCodes.h 
b/clang/include/clang/Serialization/ASTBitCodes.h
index dcfa4ac0c1967..d1a0eba943039 100644
--- a/clang/include/clang/Serialization/ASTBitCodes.h
+++ b/clang/include/clang/Serialization/ASTBitCodes.h
@@ -775,6 +775,9 @@ enum ASTRecordTypes {
   /// Record code for lexical and visible block for delayed namespace in
   /// reduced BMI.
   DELAYED_NAMESPACE_LEXICAL_VISIBLE_RECORD = 68,
+
+  /// Record code for \#pragma clang unsafe_buffer_usage begin/end
+  PP_UNSAFE_BUFFER_USAGE = 69,
 };
 
 /// Record types used within a source manager block.
diff --git a/clang/lib/Lex/Preprocessor.cpp b/clang/lib/Lex/Preprocessor.cpp
index 0b70192743a39..6a41e3d4138aa 100644
--- a/clang/lib/Lex/Preprocessor.cpp
+++ b/clang/lib/Lex/Preprocessor.cpp
@@ -58,6 +58,7 @@
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/iterator_range.h"
 #include "llvm/Support/Capacity.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/MemoryBuffer.h"
@@ -1483,26 +1484,41 @@ void Preprocessor::emitFinalMacroWarning(const Token 
&Identifier,
 }
 
 bool Preprocessor::isSafeBufferOptOut(const SourceManager &SourceMgr,
-   const SourceLocation &Loc) const {
-  // Try to find a region in `SafeBufferOptOutMap` where `Loc` is in:
-  auto FirstRegionEndingAfterLoc = llvm::partition_point(
-  SafeBufferOptOutMap,
-  [&SourceMgr,
-

[clang] [llvm] [C++23] [CLANG] Adding C++23 constexpr math functions: fmin, fmax and frexp. (PR #88978)

2024-05-16 Thread Hubert Tong via cfe-commits


@@ -14574,9 +14574,17 @@ bool FloatExprEvaluator::VisitCallExpr(const CallExpr 
*E) {
   default:
 return false;
 
+  case Builtin::BI__builtin_frexpl:
+// AIX library function `frexpl` has 'long double' type and not
+// PPCDoubleDouble type. To make sure we generate the right value, don't
+// constant evaluate it and instead defer to a libcall.
+if (Info.Ctx.getTargetInfo().getTriple().isPPC() &&
+(&Info.Ctx.getTargetInfo().getLongDoubleFormat() !=
+ &llvm::APFloat::PPCDoubleDouble()))
+  return false;
+LLVM_FALLTHROUGH;
   case Builtin::BI__builtin_frexp:
-  case Builtin::BI__builtin_frexpf:
-  case Builtin::BI__builtin_frexpl: {
+  case Builtin::BI__builtin_frexpf: {

hubert-reinterpretcast wrote:

> Does the evaluation produce the same results as would happen at runtime 
> despite the different format?

There is no different format. The default format for the `long double` type on 
AIX (and the only one supported by Clang for AIX) is IEEE double.

The IR generated for basic `long double` operations might clarify: 
https://godbolt.org/z/W4jqr6Kva

https://github.com/llvm/llvm-project/pull/88978
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL] support packoffset in clang codeGen (PR #91999)

2024-05-16 Thread Xiang Li via cfe-commits

python3kgae wrote:

> > This PR will not change this. The padding will only be added when required.
> 
> _That's the problem_
> 
> > ```hlsl
> > cbuffer {
> >   float F;
> >   float2 V;
> > }
> > ```
> > 
> > 
> > 
> >   
> > 
> > 
> >   
> > 
> > 
> > 
> >   
> > will still got
> > ```llvm
> > type { float, <2 x float>}
> > ```
> 
> And there will implicitly be padding between the two elements based on what 
> data layout does because the vector will be 64-bit aligned, which _is not_ 
> how cbuffers work.
> 
> But that's actually not the biggest problem here. The biggest problem is that 
> we shouldn't add padding for `packoffset`, but not for things that are 
> implicitly laid out, and we should have a plan for how we lower this before 
> we do any of this.
> 
> Your design document that you based this off of explicitly excluded all the 
> IR representations. We shouldn't write this code until the design doc is 
> updated with the IR and lowering design.

This will only affect a compiler generated struct for cbuffer layout. It should 
not affect any other struct layout of the compiler.

https://github.com/llvm/llvm-project/pull/91999
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Implement provisional wording for CWG2398 regarding packs (PR #90820)

2024-05-16 Thread Mehdi Amini via cfe-commits

joker-eph wrote:

Seems like a bot is broken: 
https://lab.llvm.org/buildbot/#/builders/271/builds/7701 ; can you check?

https://github.com/llvm/llvm-project/pull/90820
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Bounds-Safety] Reserve slot in SanitizerHandler enum for Bounds-Safety (PR #91032)

2024-05-16 Thread Dan Liew via cfe-commits

https://github.com/delcypher closed 
https://github.com/llvm/llvm-project/pull/91032
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 84abe0a - [Bounds-Safety] Reserve slot in SanitizerHandler enum for Bounds-Safety (#91032)

2024-05-16 Thread via cfe-commits

Author: Dan Liew
Date: 2024-05-16T15:24:11-07:00
New Revision: 84abe0a6d4face73c15ed6344be74ae231f18718

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

LOG: [Bounds-Safety] Reserve slot in SanitizerHandler enum for Bounds-Safety 
(#91032)

Due to how `CodeGenFunction::EmitTrapCheck` is implemented
`SanitizerHandler` with numeric value 0x19 needs to be reserved because
`-fbounds-safety` generates trap instructions with that value embedded
in the trap instructions for x86_64 and arm64 just like for UBSan traps.

** x86_64 **

```
ud1l   0x19(%eax), %eax
```

** arm64 **

```
brk#0x5519
```

To avoid upstream Clang and AppleClang diverging their ABIs for
`-fbounds-safety` the slot is being reserved in this patch.

`SanitizerHandler::BoundsSafety` currently has no uses in the code but
uses will be introduced when the CodeGen side of `-fbounds-safety`'s
implementation is upstreamed.

rdar://126884014

Co-authored-by: Dan Liew 

Added: 


Modified: 
clang/lib/CodeGen/CodeGenFunction.h

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenFunction.h 
b/clang/lib/CodeGen/CodeGenFunction.h
index 362f4a5fe72a6..5f3ee7eb943f9 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -137,7 +137,8 @@ enum TypeEvaluationKind {
   SANITIZER_CHECK(SubOverflow, sub_overflow, 0)
\
   SANITIZER_CHECK(TypeMismatch, type_mismatch, 1)  
\
   SANITIZER_CHECK(AlignmentAssumption, alignment_assumption, 0)
\
-  SANITIZER_CHECK(VLABoundNotPositive, vla_bound_not_positive, 0)
+  SANITIZER_CHECK(VLABoundNotPositive, vla_bound_not_positive, 0)  
\
+  SANITIZER_CHECK(BoundsSafety, bounds_safety, 0)
 
 enum SanitizerHandler {
 #define SANITIZER_CHECK(Enum, Name, Version) Enum,



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


[clang] [HLSL] support packoffset in clang codeGen (PR #91999)

2024-05-16 Thread Chris B via cfe-commits

llvm-beanz wrote:

> This PR will not change this. The padding will only be added when required.

_That's the problem_

> 
> ```hlsl
> cbuffer {
>   float F;
>   float2 V;
> }
> ```
> 
> will still got
> 
> ```llvm
> type { float, <2 x float>}
> ```

And there will implicitly be padding between the two elements based on what 
data layout does because the vector will be 64-bit aligned, which _is not_ how 
cbuffers work.

But that's actually not the biggest problem here. The biggest problem is that 
we shouldn't add padding for `packoffset`, but not for things that are 
implicitly laid out, and we should have a plan for how we lower this before we 
do any of this.

Your design document that you based this off of explicitly excluded all the IR 
representations. We shouldn't write this code until the design doc is updated 
with the IR and lowering design.


https://github.com/llvm/llvm-project/pull/91999
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [OpenCL] Put constant initializer globals into constant addrspace (PR #90048)

2024-05-16 Thread Eli Friedman via cfe-commits


@@ -535,20 +535,23 @@ void AggExprEmitter::EmitArrayInit(Address DestPtr, 
llvm::ArrayType *AType,
   elementType.isTriviallyCopyableType(CGF.getContext())) {
 CodeGen::CodeGenModule &CGM = CGF.CGM;
 ConstantEmitter Emitter(CGF);
-LangAS AS = ArrayQTy.getAddressSpace();
+QualType GVArrayQTy = CGM.getContext().getAddrSpaceQualType(
+CGM.getContext().removeAddrSpaceQualType(ArrayQTy),

efriedma-quic wrote:

I think it's a bug in removeAddrSpaceQualType(): it needs to special-case 
arrays.  Arrays are weird because qualifiers on the element type also count as 
qualifiers on the type, so getSingleStepDesugaredType() can't remove the sugar 
on arrays.  So it needs to strip the qualifier off the element type, then 
reconstruct the array type.  Maybe it can use 
ASTContext::getUnqualifiedArrayType.

https://github.com/llvm/llvm-project/pull/90048
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL] support packoffset in clang codeGen (PR #91999)

2024-05-16 Thread Xiang Li via cfe-commits

python3kgae wrote:

> > You can use `type <{ float, <2 x float>}>` if you need the tightly-packed 
> > layout.
> 
> I think we need to figure out how we're going to lower this too. Loading from 
> this memory space requires loading 128 bytes at a time, and we need to slice 
> it down to just the parts of the structure we need.
> 
> @bogner is working on the lowering logic, so I'd like to make sure what we 
> capture at the IR level is appropriate for what he needs in the DirectX 
> backend.

For the offset calculation in backend, we already added
https://github.com/llvm/llvm-project/blob/main/llvm/lib/Target/DirectX/CBufferDataLayout.h#L29

Not sure how spirv side works though.
It will need something to calculate the offset for legacy cbuffer layout as 
well.

In theory, we could mutate the struct types by add paddings to implement legacy 
cbuffer layout for data layout. But it is a little hacky since it will need to 
mutate existing struct types.

This PR doesn't mutate any existing type, since the struct is created for 
cbuffer layout only.

https://github.com/llvm/llvm-project/pull/91999
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Sema] Warn consecutive builtin comparisons in an expression (PR #92200)

2024-05-16 Thread Youngsuk Kim via cfe-commits

https://github.com/JOE1994 edited 
https://github.com/llvm/llvm-project/pull/92200
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [clang][dataflow] Make `CNFFormula` externally accessible. (PR #92401)

2024-05-16 Thread Gábor Horváth via cfe-commits

https://github.com/Xazax-hun approved this pull request.


https://github.com/llvm/llvm-project/pull/92401
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL] support packoffset in clang codeGen (PR #91999)

2024-05-16 Thread Xiang Li via cfe-commits

https://github.com/python3kgae edited 
https://github.com/llvm/llvm-project/pull/91999
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL] support packoffset in clang codeGen (PR #91999)

2024-05-16 Thread Xiang Li via cfe-commits

https://github.com/python3kgae edited 
https://github.com/llvm/llvm-project/pull/91999
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [libcxxabi] [llvm] Add support for WASI builds (PR #91051)

2024-05-16 Thread Luca Versari via cfe-commits

veluca93 wrote:

Ping

(I suspect that the assigned reviewers are likely not the most appropriate, but 
I would be unsure on how to change them and to whom)

https://github.com/llvm/llvm-project/pull/91051
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][CodeGen] Remove unused LValue::getAddress CGF arg. (PR #92465)

2024-05-16 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-codegen

@llvm/pr-subscribers-clang

Author: Ahmed Bougacha (ahmedbougacha)


Changes

This is in effect a revert of f139ae3d93797, as we have since gained a more 
sophisticated way of doing extra IRGen with the addition of RawAddress in #86923.

---

Patch is 112.37 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/92465.diff


22 Files Affected:

- (modified) clang/lib/CodeGen/CGAtomic.cpp (+6-6) 
- (modified) clang/lib/CodeGen/CGBlocks.cpp (+1-1) 
- (modified) clang/lib/CodeGen/CGBuiltin.cpp (+5-5) 
- (modified) clang/lib/CodeGen/CGCall.cpp (+14-14) 
- (modified) clang/lib/CodeGen/CGClass.cpp (+6-6) 
- (modified) clang/lib/CodeGen/CGDecl.cpp (+12-14) 
- (modified) clang/lib/CodeGen/CGException.cpp (+1-2) 
- (modified) clang/lib/CodeGen/CGExpr.cpp (+44-45) 
- (modified) clang/lib/CodeGen/CGExprAgg.cpp (+12-13) 
- (modified) clang/lib/CodeGen/CGExprCXX.cpp (+8-8) 
- (modified) clang/lib/CodeGen/CGExprComplex.cpp (+5-5) 
- (modified) clang/lib/CodeGen/CGExprScalar.cpp (+10-10) 
- (modified) clang/lib/CodeGen/CGNonTrivialStruct.cpp (+9-9) 
- (modified) clang/lib/CodeGen/CGObjC.cpp (+9-9) 
- (modified) clang/lib/CodeGen/CGOpenMPRuntime.cpp (+43-48) 
- (modified) clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp (+8-8) 
- (modified) clang/lib/CodeGen/CGStmt.cpp (+6-7) 
- (modified) clang/lib/CodeGen/CGStmtOpenMP.cpp (+72-84) 
- (modified) clang/lib/CodeGen/CGValue.h (+3-6) 
- (modified) clang/lib/CodeGen/CodeGenFunction.cpp (+2-2) 
- (modified) clang/lib/CodeGen/Targets/NVPTX.cpp (+1-1) 
- (modified) clang/lib/CodeGen/Targets/X86.cpp (+1-1) 


``diff
diff --git a/clang/lib/CodeGen/CGAtomic.cpp b/clang/lib/CodeGen/CGAtomic.cpp
index 07452b18a85ea..ab3b7a0f97f01 100644
--- a/clang/lib/CodeGen/CGAtomic.cpp
+++ b/clang/lib/CodeGen/CGAtomic.cpp
@@ -150,7 +150,7 @@ namespace {
 Address getAtomicAddress() const {
   llvm::Type *ElTy;
   if (LVal.isSimple())
-ElTy = LVal.getAddress(CGF).getElementType();
+ElTy = LVal.getAddress().getElementType();
   else if (LVal.isBitField())
 ElTy = LVal.getBitFieldAddress().getElementType();
   else if (LVal.isVectorElt())
@@ -363,7 +363,7 @@ bool AtomicInfo::requiresMemSetZero(llvm::Type *type) const 
{
 
 bool AtomicInfo::emitMemSetZeroIfNecessary() const {
   assert(LVal.isSimple());
-  Address addr = LVal.getAddress(CGF);
+  Address addr = LVal.getAddress();
   if (!requiresMemSetZero(addr.getElementType()))
 return false;
 
@@ -1603,7 +1603,7 @@ Address AtomicInfo::materializeRValue(RValue rvalue) 
const {
   LValue TempLV = CGF.MakeAddrLValue(CreateTempAlloca(), getAtomicType());
   AtomicInfo Atomics(CGF, TempLV);
   Atomics.emitCopyIntoMemory(rvalue);
-  return TempLV.getAddress(CGF);
+  return TempLV.getAddress();
 }
 
 llvm::Value *AtomicInfo::getScalarRValValueOrNull(RValue RVal) const {
@@ -1951,7 +1951,7 @@ void CodeGenFunction::EmitAtomicStore(RValue rvalue, 
LValue dest,
   // maybe for address-space qualification.
   assert(!rvalue.isAggregate() ||
  rvalue.getAggregateAddress().getElementType() ==
- dest.getAddress(*this).getElementType());
+ dest.getAddress().getElementType());
 
   AtomicInfo atomics(*this, dest);
   LValue LVal = atomics.getAtomicLValue();
@@ -2024,10 +2024,10 @@ std::pair 
CodeGenFunction::EmitAtomicCompareExchange(
   // maybe for address-space qualification.
   assert(!Expected.isAggregate() ||
  Expected.getAggregateAddress().getElementType() ==
- Obj.getAddress(*this).getElementType());
+ Obj.getAddress().getElementType());
   assert(!Desired.isAggregate() ||
  Desired.getAggregateAddress().getElementType() ==
- Obj.getAddress(*this).getElementType());
+ Obj.getAddress().getElementType());
   AtomicInfo Atomics(*this, Obj);
 
   return Atomics.EmitAtomicCompareExchange(Expected, Desired, Success, Failure,
diff --git a/clang/lib/CodeGen/CGBlocks.cpp b/clang/lib/CodeGen/CGBlocks.cpp
index 2742c39965b2c..bf50f2025de57 100644
--- a/clang/lib/CodeGen/CGBlocks.cpp
+++ b/clang/lib/CodeGen/CGBlocks.cpp
@@ -927,7 +927,7 @@ llvm::Value *CodeGenFunction::EmitBlockLiteral(const 
CGBlockInfo &blockInfo) {
   /*RefersToEnclosingVariableOrCapture*/ CI.isNested(),
   type.getNonReferenceType(), VK_LValue,
   SourceLocation());
-  src = EmitDeclRefLValue(&declRef).getAddress(*this);
+  src = EmitDeclRefLValue(&declRef).getAddress();
 };
 
 // For byrefs, we just write the pointer to the byref struct into
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index e251091c6ce3e..ba94bf89e4751 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -5609,8 +5609,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 llvm::Value *Queue = EmitScalarExpr(E-

[clang] [clang][Sema] Warn consecutive builtin comparisons in an expression (PR #92200)

2024-05-16 Thread Youngsuk Kim via cfe-commits


@@ -215,3 +215,10 @@ namespace PR20735 {
 // fix-it:"{{.*}}":{[[@LINE-9]]:20-[[@LINE-9]]:20}:")"
   }
 }
+
+void consecutive_builtin_compare(int x, int y, int z) {
+  (void)(x < y < z);  // expected-warning {{comparisons like 'X<=Y<=Z' don't 
have their mathematical meaning}}
+  (void)(x < y > z);  // expected-warning {{comparisons like 'X<=Y<=Z' don't 
have their mathematical meaning}}
+  (void)(x < y <= z); // expected-warning {{comparisons like 'X<=Y<=Z' don't 
have their mathematical meaning}}
+  (void)(x <= y > z); // expected-warning {{comparisons like 'X<=Y<=Z' don't 
have their mathematical meaning}}

JOE1994 wrote:

(I'll refer to each of the 3 cases mentioned in the above comment as case1, 
case2, and case 3)

I pushed a commit that adds 2 `no-warning` test lines for case1.
It's unlikely for one to write `((x < y) >= z)` and believe it to have 
mathematical meaning of `(x < y) AND (y >= z)`.

I limited the scope of this PR to diagnosing consecutive "built-in" comparisons 
(as per the PR title).
Thus, the current implementation does not diagnose case 2.

I don't have the capacity to further work on making clang diagnose case 2 but 
not case 3.
I added a TODO note at the bottom of the test lines for now.

FYI, gcc doesn't diagnose any of case1, case2, or case 3.

https://github.com/llvm/llvm-project/pull/92200
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [OpenCL] Put constant initializer globals into constant addrspace (PR #90048)

2024-05-16 Thread Changpeng Fang via cfe-commits


@@ -535,20 +535,23 @@ void AggExprEmitter::EmitArrayInit(Address DestPtr, 
llvm::ArrayType *AType,
   elementType.isTriviallyCopyableType(CGF.getContext())) {
 CodeGen::CodeGenModule &CGM = CGF.CGM;
 ConstantEmitter Emitter(CGF);
-LangAS AS = ArrayQTy.getAddressSpace();
+QualType GVArrayQTy = CGM.getContext().getAddrSpaceQualType(
+CGM.getContext().removeAddrSpaceQualType(ArrayQTy),

changpeng wrote:

We saw a regression caused by this PR. It is a soft hang in 
CGM.getContext().removeAddrSpaceQualType.
Specifically it is in the following while loop:
while (T.hasAddressSpace()) {
TypeNode = Quals.strip(T);

// If the type no longer has an address space after stripping qualifiers,
// jump out.
if (!QualType(TypeNode, 0).hasAddressSpace())
  break;

// There might be sugar in the way. Strip it and try again.
T = T.getSingleStepDesugaredType(*this);
  }
We found that "T == T.getSingleStepDesugaredType(*this);" and this it could not 
proceed.

I am not sure whether we should break out this loop when "T == 
T.getSingleStepDesugaredType(*this)"
or something else is wrong that we should never see such case.

Here is the dump of T:
ConstantArrayType 0x65b40640 '__private ulong[16]' 16
`-QualType 0x65b403f8 '__private ulong' __private
  `-ElaboratedType 0x65b3ff40 'ulong' sugar imported
`-TypedefType 0x65b3fef0 'ulong' sugar imported
  |-Typedef 0x65b3fe80 'ulong'
  `-BuiltinType 0x6583f430 'unsigned long'

https://github.com/llvm/llvm-project/pull/90048
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Sema] Warn consecutive builtin comparisons in an expression (PR #92200)

2024-05-16 Thread Youngsuk Kim via cfe-commits

https://github.com/JOE1994 updated 
https://github.com/llvm/llvm-project/pull/92200

>From 2c7f9a083c129df70a79d019286b6a29643a8973 Mon Sep 17 00:00:00 2001
From: Youngsuk Kim 
Date: Tue, 14 May 2024 17:42:59 -0500
Subject: [PATCH 1/4] [clang][Sema] Warn consecutive builtin comparisons in an
 expression

Made the following decisions for consistency with `gcc 14.1`:
* Add warning under -Wparentheses
* Set the warning to DefaultIgnore, although -Wparentheses is enabled by default
  * This warning is only issued when -Wparentheses is explicitly enabled
(via -Wparentheses or -Wall)

Closes #20456
---
 clang/docs/ReleaseNotes.rst  | 3 +++
 clang/include/clang/Basic/DiagnosticSemaKinds.td | 4 
 clang/lib/Sema/SemaExpr.cpp  | 5 +
 clang/test/Sema/parentheses.cpp  | 7 +++
 4 files changed, 19 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ae699ebfc6038..13d58e69aeeb7 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -487,6 +487,9 @@ Improvements to Clang's diagnostics
}
  };
 
+- Clang emits a ``-Wparentheses`` warning for expressions with consecutive 
comparisons like ``x < y < z``.
+  It was made a ``-Wparentheses`` warning to be consistent with gcc.
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 6100fba510059..612043f410890 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6911,6 +6911,10 @@ def warn_precedence_bitwise_conditional : Warning<
 def note_precedence_conditional_first : Note<
   "place parentheses around the '?:' expression to evaluate it first">;
 
+def warn_consecutive_comparison : Warning<
+  "comparisons like 'X<=Y<=Z' don't have their mathematical meaning">,
+  InGroup, DefaultIgnore;
+
 def warn_enum_constant_in_bool_context : Warning<
   "converting the enum constant to a boolean">,
   InGroup, DefaultIgnore;
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index ec84798e4ce60..fab34f4fa3e14 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -14878,6 +14878,11 @@ ExprResult Sema::CreateBuiltinBinOp(SourceLocation 
OpLoc,
   case BO_GT:
 ConvertHalfVec = true;
 ResultTy = CheckCompareOperands(LHS, RHS, OpLoc, Opc);
+
+if (const auto *BI = dyn_cast(LHSExpr))
+  if (BI->isComparisonOp())
+Diag(OpLoc, diag::warn_consecutive_comparison);
+
 break;
   case BO_EQ:
   case BO_NE:
diff --git a/clang/test/Sema/parentheses.cpp b/clang/test/Sema/parentheses.cpp
index 324d9b5f1e414..8e546461fb643 100644
--- a/clang/test/Sema/parentheses.cpp
+++ b/clang/test/Sema/parentheses.cpp
@@ -215,3 +215,10 @@ namespace PR20735 {
 // fix-it:"{{.*}}":{[[@LINE-9]]:20-[[@LINE-9]]:20}:")"
   }
 }
+
+void consecutive_builtin_compare(int x, int y, int z) {
+  (void)(x < y < z);  // expected-warning {{comparisons like 'X<=Y<=Z' don't 
have their mathematical meaning}}
+  (void)(x < y > z);  // expected-warning {{comparisons like 'X<=Y<=Z' don't 
have their mathematical meaning}}
+  (void)(x < y <= z); // expected-warning {{comparisons like 'X<=Y<=Z' don't 
have their mathematical meaning}}
+  (void)(x <= y > z); // expected-warning {{comparisons like 'X<=Y<=Z' don't 
have their mathematical meaning}}
+}

>From b3cc457efc40a345d4b67c776edd470e35f73de2 Mon Sep 17 00:00:00 2001
From: Youngsuk Kim 
Date: Wed, 15 May 2024 13:20:06 -0400
Subject: [PATCH 2/4] Update clang/lib/Sema/SemaExpr.cpp

Co-authored-by: Aaron Ballman 
---
 clang/lib/Sema/SemaExpr.cpp | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index fab34f4fa3e14..b4c54a3da42c0 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -14879,9 +14879,8 @@ ExprResult Sema::CreateBuiltinBinOp(SourceLocation 
OpLoc,
 ConvertHalfVec = true;
 ResultTy = CheckCompareOperands(LHS, RHS, OpLoc, Opc);
 
-if (const auto *BI = dyn_cast(LHSExpr))
-  if (BI->isComparisonOp())
-Diag(OpLoc, diag::warn_consecutive_comparison);
+if (const auto *BI = dyn_cast(LHSExpr); BI && 
BI->isComparisonOp())
+  Diag(OpLoc, diag::warn_consecutive_comparison);
 
 break;
   case BO_EQ:

>From 8df35dcf7b802ce8e280930224575077a08e0541 Mon Sep 17 00:00:00 2001
From: Youngsuk Kim 
Date: Wed, 15 May 2024 12:53:38 -0500
Subject: [PATCH 3/4] Remove DefaultIgnore + clang-format

---
 clang/include/clang/Basic/DiagnosticSemaKinds.td  | 2 +-
 clang/lib/Sema/SemaExpr.cpp   | 3 ++-
 clang/test/Sema/bool-compare.c| 4 ++--
 clang/test/SemaCXX/bool-compare.cpp   | 4 ++--
 clang/test/SemaCXX/cxx2a-adl-only-template-id.cpp | 2 +-
 clang/test/SemaTemplate/typo-dependent-name.cpp   |

[clang] [HLSL] support packoffset in clang codeGen (PR #91999)

2024-05-16 Thread Xiang Li via cfe-commits

python3kgae wrote:

> > Could you explain more about can't put any vectors or matrices into the 
> > cbuffer structure type?
> 
> Consider this example (regardless of packoffset):
> 
> ```hlsl
> cbuffer {
>   float F;
>   float2 V;
> }
> ```
> 
> The layout for this is basically:
> 
> ```c
> struct {
>   float F;
>   float Vx; // v.x
>   float Vy; // v.y
> };
> ```
> 
> These elements are all packed.
> 
> If you translate this to an IR struct you get something like:
> 
> ```llvm
> type { float, <2 x float>}
> ```
> 
> The data layout will insert 4-bytes of padding between the float and the 
> vector because the vector needs to be properly aligned.

This PR will not change this.
The padding will only be added when required.
```hlsl
cbuffer {
  float F;
  float2 V;
}
```
will still got
```llvm
type { float, <2 x float>}
```
But 
```hlsl
cbuffer {
  float3 F;
  float2 V;
}
```
will got padding, because it crossed 4dword.
```llvm
type { <3 x float>, [4 x i8],  <2 x float>}
```


https://github.com/llvm/llvm-project/pull/91999
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [llvm] [ConstantFolding] Canonicalize constexpr GEPs to i8 (PR #89872)

2024-05-16 Thread Arthur Eubanks via cfe-commits

https://github.com/aeubanks approved this pull request.

we've resolved the performance regression from the previous patch internally, 
thanks for waiting!

https://github.com/llvm/llvm-project/pull/89872
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Safe Buffers] Serialize unsafe_buffer_usage pragmas (PR #92031)

2024-05-16 Thread Ziqing Luo via cfe-commits


@@ -1551,6 +1567,58 @@ bool 
Preprocessor::isPPInSafeBufferOptOutRegion(SourceLocation &StartLoc) {
   return InSafeBufferOptOutRegion;
 }
 
+SmallVector
+Preprocessor::serializeSafeBufferOptOutMap() const {
+  assert(!InSafeBufferOptOutRegion &&

ziqingluo-90 wrote:

Oh,  I'm sorry,  they are not warnings, they are errors: 
https://github.com/llvm/llvm-project/blob/c79690040acf5bb3d857558b0878db47f7f23dc3/clang/lib/Lex/Pragma.cpp#L1265

https://github.com/llvm/llvm-project/pull/92031
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [compiler-rt] Realtime Sanitizer: Introduce RADSan backend (PR #92460)

2024-05-16 Thread Chris Apple via cfe-commits

https://github.com/cjappl edited https://github.com/llvm/llvm-project/pull/92460
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] Realtime Sanitizer: Introduce RADSan backend (PR #92460)

2024-05-16 Thread Chris Apple via cfe-commits

https://github.com/cjappl reopened 
https://github.com/llvm/llvm-project/pull/92460
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] Realtime Sanitizer: Introduce RADSan backend (PR #92460)

2024-05-16 Thread Chris Apple via cfe-commits

https://github.com/cjappl closed https://github.com/llvm/llvm-project/pull/92460
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] Realtime Sanitizer: Introduce RADSan backend (PR #92460)

2024-05-16 Thread Chris Apple via cfe-commits

cjappl wrote:

Pinging possibly interested parties for review. 

@yln @vitalybuka @Sirraide @AaronBallman @dougsonos @davidtrevelyan 

Please feel free to add more, we don't know who all may be interested. Thanks 
in advance

https://github.com/llvm/llvm-project/pull/92460
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [analyzer] Adding taint analysis capability to unix.Malloc checker (PR #92420)

2024-05-16 Thread Artem Dergachev via cfe-commits

haoNoQ wrote:

I think there should be a way to enable/disable this check separately because 
memory exhaustion / denial of service isn't necessarily something you care 
about when you enable taint analysis.

It's essential for web servers when the attacker is interested in interrupting 
their operation but not necessarily for personal devices where the attacker is 
interested only in gaining control of the device. For these applications it's 
more important to catch cases where malloc size and index used for access are 
coming from "different sources", eg. one is tainted and another isn't, doesn't 
matter which one.

For the same reason, I think the error node needs to be non-fatal. If you make 
it fatal, you lose the opportunity to catch this other type of bugs on the same 
path, which are 50% likely to be found on the same path, and are arguably much 
more severe.

Of course when your new check is disabled there won't be a sink so we'll still 
catch the other bug. But we don't actually want it to work this way; we'd 
rather have the user control the warnings they want to see with simple on-off 
flags without weird interactions between those flags.

So sink generation should be mostly a thing that "modeling" checkers do, when 
they're confident that we simply cannot continue analysis further. In this case 
I don't really see any problems with continuing the analysis so it should 
probably be a non-fatal error.

https://github.com/llvm/llvm-project/pull/92420
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] Realtime Sanitizer: Introduce RADSan backend (PR #92460)

2024-05-16 Thread Chris Apple via cfe-commits


@@ -32,6 +32,9 @@ set(ALL_ASAN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} 
${ARM64} ${RISCV64}
 ${LOONGARCH64})
 set(ALL_ASAN_ABI_SUPPORTED_ARCH ${X86_64} ${ARM64} ${ARM64_32})
 set(ALL_DFSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64} ${LOONGARCH64})
+set(ALL_RADSAN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${RISCV64}
+${MIPS32} ${MIPS64} ${PPC64} ${S390X} ${SPARC} ${SPARCV9} ${HEXAGON}
+${LOONGARCH64})

cjappl wrote:

This was copied from ASAN, is this acceptable? We don't have all architectures 
to test, although we think that our interceptors are simple enough to work on 
any machine (no platform specific assembly in our code, for example)

https://github.com/llvm/llvm-project/pull/92460
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   3   4   5   >