[clang-tools-extra] [clang-doc] switched from using relative to absolute paths (PR #93281)

2024-06-30 Thread via cfe-commits


@@ -7,6 +7,7 @@
 // RUN: FileCheck %s -input-file=%t/docs/GlobalNamespace/Rectangle.html 
-check-prefix=HTML-RECTANGLE
 // RUN: FileCheck %s -input-file=%t/docs/GlobalNamespace/Circle.html 
-check-prefix=HTML-CIRCLE
 
+// JSON-INDEX: var RootPath = "{{.*}}";

PeterChou1 wrote:

This isn't a url, this variable is a path to the directory where clang-doc is 
built from. I wanted the html to still render properly when viewed via the 
local filesystem so I added this export variable.
Most the changes that is reflected in this patch can only be seen once the 
browser loads the page and javascript generates the sidebar with the indexes, I 
don't think its possible to see the changes reflected unless we incorporate 
some sort javascript test framework. We could also just generate the indexes 
via the c++ html generator than we be able to see the changes.
I've added some test that test the different behaviour when we generate 
clang-doc via a relative path or an absolute one, though


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


[clang-tools-extra] [clang-doc] switched from using relative to absolute paths (PR #93281)

2024-06-30 Thread via cfe-commits

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


[clang-tools-extra] [clang-doc] switched from using relative to absolute paths (PR #93281)

2024-06-30 Thread via cfe-commits

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


[clang-tools-extra] [clang-doc] switched from using relative to absolute paths (PR #93281)

2024-06-30 Thread via cfe-commits

https://github.com/PeterChou1 updated 
https://github.com/llvm/llvm-project/pull/93281

>From f5872e7c82d097ae3c141765d3f1d7e3d0b25b82 Mon Sep 17 00:00:00 2001
From: PeterChou1 
Date: Fri, 24 May 2024 04:28:08 -0400
Subject: [PATCH 1/5] clang-doc switched from using relative to absolute paths

---
 clang-tools-extra/clang-doc/assets/index.js | 72 ++---
 1 file changed, 35 insertions(+), 37 deletions(-)

diff --git a/clang-tools-extra/clang-doc/assets/index.js 
b/clang-tools-extra/clang-doc/assets/index.js
index a5ac90f2e06e7..fe35e706cc98d 100644
--- a/clang-tools-extra/clang-doc/assets/index.js
+++ b/clang-tools-extra/clang-doc/assets/index.js
@@ -1,48 +1,46 @@
-// Append using posix-style a file name or directory to Base
-function append(Base, New) {
-  if (!New)
-return Base;
-  if (Base)
-Base += "/";
-  Base += New;
-  return Base;
-}
-
-// Get relative path to access FilePath from CurrentDirectory
-function computeRelativePath(FilePath, CurrentDirectory) {
-  var Path = FilePath;
-  while (Path) {
-if (CurrentDirectory == Path)
-  return FilePath.substring(Path.length + 1);
-Path = Path.substring(0, Path.lastIndexOf("/"));
-  }
-
-  var Dir = CurrentDirectory;
-  var Result = "";
-  while (Dir) {
-if (Dir == FilePath)
-  break;
-Dir = Dir.substring(0, Dir.lastIndexOf("/"));
-Result = append(Result, "..")
+function genLink(Ref) {
+  var Path = 
`${window.location.protocol}//${window.location.host}/${Ref.Path}`;
+  if (Ref.RefType !== "namespace") {
+if (Ref.Path === "") {
+  Path = `${Path}${Ref.Name}.html`;
+}
+else {
+  Path = `${Path}/${Ref.Name}.html`;
+}
   }
-  Result = append(Result, FilePath.substring(Dir.length))
-  return Result;
-}
-
-function genLink(Ref, CurrentDirectory) {
-  var Path = computeRelativePath(Ref.Path, CurrentDirectory);
-  if (Ref.RefType == "namespace")
-Path = append(Path, "index.html");
-  else
-Path = append(Path, Ref.Name + ".html")
 
-ANode = document.createElement("a");
+  ANode = document.createElement("a");
   ANode.setAttribute("href", Path);
   var TextNode = document.createTextNode(Ref.Name);
   ANode.appendChild(TextNode);
   return ANode;
 }
 
+function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) {
+  // Out will store the HTML elements that Index requires to be generated
+  var Out = [];
+  if (Index.Name) {
+var SpanNode = document.createElement("span");
+var TextNode = document.createTextNode(Index.Name);
+SpanNode.appendChild(genLink(Index));
+Out.push(SpanNode);
+  }
+  if (Index.Children.length == 0)
+return Out;
+  // Only the outermost list should use ol, the others should use ul
+  var ListNodeName = IsOutermostList ? "ol" : "ul";
+  var ListNode = document.createElement(ListNodeName);
+  for (Child of Index.Children) {
+var LiNode = document.createElement("li");
+ChildNodes = genHTMLOfIndex(Child, CurrentDirectory, false);
+for (Node of ChildNodes)
+  LiNode.appendChild(Node);
+ListNode.appendChild(LiNode);
+  }
+  Out.push(ListNode);
+  return Out;
+}
+
 function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) {
   // Out will store the HTML elements that Index requires to be generated
   var Out = [];

>From a22609f75064194604e476a12bc8154676dacfb9 Mon Sep 17 00:00:00 2001
From: PeterChou1 
Date: Fri, 24 May 2024 05:10:03 -0400
Subject: [PATCH 2/5] remove duplicate function

---
 clang-tools-extra/clang-doc/assets/index.js | 24 -
 1 file changed, 24 deletions(-)

diff --git a/clang-tools-extra/clang-doc/assets/index.js 
b/clang-tools-extra/clang-doc/assets/index.js
index fe35e706cc98d..b013418c82093 100644
--- a/clang-tools-extra/clang-doc/assets/index.js
+++ b/clang-tools-extra/clang-doc/assets/index.js
@@ -16,30 +16,6 @@ function genLink(Ref) {
   return ANode;
 }
 
-function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) {
-  // Out will store the HTML elements that Index requires to be generated
-  var Out = [];
-  if (Index.Name) {
-var SpanNode = document.createElement("span");
-var TextNode = document.createTextNode(Index.Name);
-SpanNode.appendChild(genLink(Index));
-Out.push(SpanNode);
-  }
-  if (Index.Children.length == 0)
-return Out;
-  // Only the outermost list should use ol, the others should use ul
-  var ListNodeName = IsOutermostList ? "ol" : "ul";
-  var ListNode = document.createElement(ListNodeName);
-  for (Child of Index.Children) {
-var LiNode = document.createElement("li");
-ChildNodes = genHTMLOfIndex(Child, CurrentDirectory, false);
-for (Node of ChildNodes)
-  LiNode.appendChild(Node);
-ListNode.appendChild(LiNode);
-  }
-  Out.push(ListNode);
-  return Out;
-}
 
 function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) {
   // Out will store the HTML elements that Index requires to be generated

>From be0fb1acdd97a07e665b61fbba44d32dd40e1b94 Mon Sep 17 00:00:00 2001
From: PeterChou1 
Date: Sa

[clang] [llvm] Add f8E4M3 IEEE 754 type to llvm (PR #97179)

2024-06-30 Thread Matt Arsenault via cfe-commits

arsenm wrote:

Title and description needs rewording. This isn't adding the type "to llvm" 
which would imply adding the IR type, but only to APFloat 

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


[clang] [llvm] Add f8E4M3 IEEE 754 type to llvm (PR #97179)

2024-06-30 Thread Thorsten Schütt via cfe-commits

tschuett wrote:

For reference the last type added:
https://github.com/llvm/llvm-project/pull/95392

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


[clang-tools-extra] [clang-doc] switched from using relative to absolute paths (PR #93281)

2024-06-30 Thread via cfe-commits

https://github.com/PeterChou1 updated 
https://github.com/llvm/llvm-project/pull/93281

>From f5872e7c82d097ae3c141765d3f1d7e3d0b25b82 Mon Sep 17 00:00:00 2001
From: PeterChou1 
Date: Fri, 24 May 2024 04:28:08 -0400
Subject: [PATCH 1/6] clang-doc switched from using relative to absolute paths

---
 clang-tools-extra/clang-doc/assets/index.js | 72 ++---
 1 file changed, 35 insertions(+), 37 deletions(-)

diff --git a/clang-tools-extra/clang-doc/assets/index.js 
b/clang-tools-extra/clang-doc/assets/index.js
index a5ac90f2e06e7..fe35e706cc98d 100644
--- a/clang-tools-extra/clang-doc/assets/index.js
+++ b/clang-tools-extra/clang-doc/assets/index.js
@@ -1,48 +1,46 @@
-// Append using posix-style a file name or directory to Base
-function append(Base, New) {
-  if (!New)
-return Base;
-  if (Base)
-Base += "/";
-  Base += New;
-  return Base;
-}
-
-// Get relative path to access FilePath from CurrentDirectory
-function computeRelativePath(FilePath, CurrentDirectory) {
-  var Path = FilePath;
-  while (Path) {
-if (CurrentDirectory == Path)
-  return FilePath.substring(Path.length + 1);
-Path = Path.substring(0, Path.lastIndexOf("/"));
-  }
-
-  var Dir = CurrentDirectory;
-  var Result = "";
-  while (Dir) {
-if (Dir == FilePath)
-  break;
-Dir = Dir.substring(0, Dir.lastIndexOf("/"));
-Result = append(Result, "..")
+function genLink(Ref) {
+  var Path = 
`${window.location.protocol}//${window.location.host}/${Ref.Path}`;
+  if (Ref.RefType !== "namespace") {
+if (Ref.Path === "") {
+  Path = `${Path}${Ref.Name}.html`;
+}
+else {
+  Path = `${Path}/${Ref.Name}.html`;
+}
   }
-  Result = append(Result, FilePath.substring(Dir.length))
-  return Result;
-}
-
-function genLink(Ref, CurrentDirectory) {
-  var Path = computeRelativePath(Ref.Path, CurrentDirectory);
-  if (Ref.RefType == "namespace")
-Path = append(Path, "index.html");
-  else
-Path = append(Path, Ref.Name + ".html")
 
-ANode = document.createElement("a");
+  ANode = document.createElement("a");
   ANode.setAttribute("href", Path);
   var TextNode = document.createTextNode(Ref.Name);
   ANode.appendChild(TextNode);
   return ANode;
 }
 
+function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) {
+  // Out will store the HTML elements that Index requires to be generated
+  var Out = [];
+  if (Index.Name) {
+var SpanNode = document.createElement("span");
+var TextNode = document.createTextNode(Index.Name);
+SpanNode.appendChild(genLink(Index));
+Out.push(SpanNode);
+  }
+  if (Index.Children.length == 0)
+return Out;
+  // Only the outermost list should use ol, the others should use ul
+  var ListNodeName = IsOutermostList ? "ol" : "ul";
+  var ListNode = document.createElement(ListNodeName);
+  for (Child of Index.Children) {
+var LiNode = document.createElement("li");
+ChildNodes = genHTMLOfIndex(Child, CurrentDirectory, false);
+for (Node of ChildNodes)
+  LiNode.appendChild(Node);
+ListNode.appendChild(LiNode);
+  }
+  Out.push(ListNode);
+  return Out;
+}
+
 function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) {
   // Out will store the HTML elements that Index requires to be generated
   var Out = [];

>From a22609f75064194604e476a12bc8154676dacfb9 Mon Sep 17 00:00:00 2001
From: PeterChou1 
Date: Fri, 24 May 2024 05:10:03 -0400
Subject: [PATCH 2/6] remove duplicate function

---
 clang-tools-extra/clang-doc/assets/index.js | 24 -
 1 file changed, 24 deletions(-)

diff --git a/clang-tools-extra/clang-doc/assets/index.js 
b/clang-tools-extra/clang-doc/assets/index.js
index fe35e706cc98d..b013418c82093 100644
--- a/clang-tools-extra/clang-doc/assets/index.js
+++ b/clang-tools-extra/clang-doc/assets/index.js
@@ -16,30 +16,6 @@ function genLink(Ref) {
   return ANode;
 }
 
-function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) {
-  // Out will store the HTML elements that Index requires to be generated
-  var Out = [];
-  if (Index.Name) {
-var SpanNode = document.createElement("span");
-var TextNode = document.createTextNode(Index.Name);
-SpanNode.appendChild(genLink(Index));
-Out.push(SpanNode);
-  }
-  if (Index.Children.length == 0)
-return Out;
-  // Only the outermost list should use ol, the others should use ul
-  var ListNodeName = IsOutermostList ? "ol" : "ul";
-  var ListNode = document.createElement(ListNodeName);
-  for (Child of Index.Children) {
-var LiNode = document.createElement("li");
-ChildNodes = genHTMLOfIndex(Child, CurrentDirectory, false);
-for (Node of ChildNodes)
-  LiNode.appendChild(Node);
-ListNode.appendChild(LiNode);
-  }
-  Out.push(ListNode);
-  return Out;
-}
 
 function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) {
   // Out will store the HTML elements that Index requires to be generated

>From be0fb1acdd97a07e665b61fbba44d32dd40e1b94 Mon Sep 17 00:00:00 2001
From: PeterChou1 
Date: Sa

[clang] [llvm] [APFloat] Add support for f8E4M3 IEEE 754 type (PR #97179)

2024-06-30 Thread Thorsten Schütt via cfe-commits

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


[clang] [llvm] [APFloat] Add support for f8E4M3 IEEE 754 type (PR #97179)

2024-06-30 Thread Thorsten Schütt via cfe-commits

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


[clang-tools-extra] [clang-doc] switched from using relative to absolute paths (PR #93281)

2024-06-30 Thread via cfe-commits

https://github.com/PeterChou1 updated 
https://github.com/llvm/llvm-project/pull/93281

>From f5872e7c82d097ae3c141765d3f1d7e3d0b25b82 Mon Sep 17 00:00:00 2001
From: PeterChou1 
Date: Fri, 24 May 2024 04:28:08 -0400
Subject: [PATCH 1/7] clang-doc switched from using relative to absolute paths

---
 clang-tools-extra/clang-doc/assets/index.js | 72 ++---
 1 file changed, 35 insertions(+), 37 deletions(-)

diff --git a/clang-tools-extra/clang-doc/assets/index.js 
b/clang-tools-extra/clang-doc/assets/index.js
index a5ac90f2e06e7..fe35e706cc98d 100644
--- a/clang-tools-extra/clang-doc/assets/index.js
+++ b/clang-tools-extra/clang-doc/assets/index.js
@@ -1,48 +1,46 @@
-// Append using posix-style a file name or directory to Base
-function append(Base, New) {
-  if (!New)
-return Base;
-  if (Base)
-Base += "/";
-  Base += New;
-  return Base;
-}
-
-// Get relative path to access FilePath from CurrentDirectory
-function computeRelativePath(FilePath, CurrentDirectory) {
-  var Path = FilePath;
-  while (Path) {
-if (CurrentDirectory == Path)
-  return FilePath.substring(Path.length + 1);
-Path = Path.substring(0, Path.lastIndexOf("/"));
-  }
-
-  var Dir = CurrentDirectory;
-  var Result = "";
-  while (Dir) {
-if (Dir == FilePath)
-  break;
-Dir = Dir.substring(0, Dir.lastIndexOf("/"));
-Result = append(Result, "..")
+function genLink(Ref) {
+  var Path = 
`${window.location.protocol}//${window.location.host}/${Ref.Path}`;
+  if (Ref.RefType !== "namespace") {
+if (Ref.Path === "") {
+  Path = `${Path}${Ref.Name}.html`;
+}
+else {
+  Path = `${Path}/${Ref.Name}.html`;
+}
   }
-  Result = append(Result, FilePath.substring(Dir.length))
-  return Result;
-}
-
-function genLink(Ref, CurrentDirectory) {
-  var Path = computeRelativePath(Ref.Path, CurrentDirectory);
-  if (Ref.RefType == "namespace")
-Path = append(Path, "index.html");
-  else
-Path = append(Path, Ref.Name + ".html")
 
-ANode = document.createElement("a");
+  ANode = document.createElement("a");
   ANode.setAttribute("href", Path);
   var TextNode = document.createTextNode(Ref.Name);
   ANode.appendChild(TextNode);
   return ANode;
 }
 
+function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) {
+  // Out will store the HTML elements that Index requires to be generated
+  var Out = [];
+  if (Index.Name) {
+var SpanNode = document.createElement("span");
+var TextNode = document.createTextNode(Index.Name);
+SpanNode.appendChild(genLink(Index));
+Out.push(SpanNode);
+  }
+  if (Index.Children.length == 0)
+return Out;
+  // Only the outermost list should use ol, the others should use ul
+  var ListNodeName = IsOutermostList ? "ol" : "ul";
+  var ListNode = document.createElement(ListNodeName);
+  for (Child of Index.Children) {
+var LiNode = document.createElement("li");
+ChildNodes = genHTMLOfIndex(Child, CurrentDirectory, false);
+for (Node of ChildNodes)
+  LiNode.appendChild(Node);
+ListNode.appendChild(LiNode);
+  }
+  Out.push(ListNode);
+  return Out;
+}
+
 function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) {
   // Out will store the HTML elements that Index requires to be generated
   var Out = [];

>From a22609f75064194604e476a12bc8154676dacfb9 Mon Sep 17 00:00:00 2001
From: PeterChou1 
Date: Fri, 24 May 2024 05:10:03 -0400
Subject: [PATCH 2/7] remove duplicate function

---
 clang-tools-extra/clang-doc/assets/index.js | 24 -
 1 file changed, 24 deletions(-)

diff --git a/clang-tools-extra/clang-doc/assets/index.js 
b/clang-tools-extra/clang-doc/assets/index.js
index fe35e706cc98d..b013418c82093 100644
--- a/clang-tools-extra/clang-doc/assets/index.js
+++ b/clang-tools-extra/clang-doc/assets/index.js
@@ -16,30 +16,6 @@ function genLink(Ref) {
   return ANode;
 }
 
-function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) {
-  // Out will store the HTML elements that Index requires to be generated
-  var Out = [];
-  if (Index.Name) {
-var SpanNode = document.createElement("span");
-var TextNode = document.createTextNode(Index.Name);
-SpanNode.appendChild(genLink(Index));
-Out.push(SpanNode);
-  }
-  if (Index.Children.length == 0)
-return Out;
-  // Only the outermost list should use ol, the others should use ul
-  var ListNodeName = IsOutermostList ? "ol" : "ul";
-  var ListNode = document.createElement(ListNodeName);
-  for (Child of Index.Children) {
-var LiNode = document.createElement("li");
-ChildNodes = genHTMLOfIndex(Child, CurrentDirectory, false);
-for (Node of ChildNodes)
-  LiNode.appendChild(Node);
-ListNode.appendChild(LiNode);
-  }
-  Out.push(ListNode);
-  return Out;
-}
 
 function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) {
   // Out will store the HTML elements that Index requires to be generated

>From be0fb1acdd97a07e665b61fbba44d32dd40e1b94 Mon Sep 17 00:00:00 2001
From: PeterChou1 
Date: Sa

[clang] 56a636f - [clang][Interp] Implement StmtExprs

2024-06-30 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-06-30T09:28:56+02:00
New Revision: 56a636f2d22890cc71f358ddc50d3e0f2b60bd9c

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

LOG: [clang][Interp] Implement StmtExprs

Added: 


Modified: 
clang/lib/AST/Interp/Compiler.cpp
clang/lib/AST/Interp/Compiler.h
clang/test/AST/Interp/literals.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/Compiler.cpp 
b/clang/lib/AST/Interp/Compiler.cpp
index 8b6f7f644a778..424f4f84a0167 100644
--- a/clang/lib/AST/Interp/Compiler.cpp
+++ b/clang/lib/AST/Interp/Compiler.cpp
@@ -3025,6 +3025,32 @@ bool Compiler::VisitCXXStdInitializerListExpr(
   return this->emitInitFieldPtr(R->getField(1u)->Offset, E);
 }
 
+template 
+bool Compiler::VisitStmtExpr(const StmtExpr *E) {
+  BlockScope BS(this);
+
+  const CompoundStmt *CS = E->getSubStmt();
+  const Stmt *Result = CS->getStmtExprResult();
+  for (const Stmt *S : CS->body()) {
+if (S != Result) {
+  if (!this->visitStmt(S))
+return false;
+  continue;
+}
+
+assert(S == Result);
+// This better produces a value (i.e. is an expression).
+if (const Expr *ResultExpr = dyn_cast(S)) {
+  if (DiscardResult)
+return this->discard(ResultExpr);
+  return this->delegate(ResultExpr);
+}
+return false;
+  }
+
+  return true;
+}
+
 template  bool Compiler::discard(const Expr *E) {
   OptionScope Scope(this, /*NewDiscardResult=*/true,
  /*NewInitializing=*/false);

diff  --git a/clang/lib/AST/Interp/Compiler.h b/clang/lib/AST/Interp/Compiler.h
index 89e36f9201a41..d188ce2200664 100644
--- a/clang/lib/AST/Interp/Compiler.h
+++ b/clang/lib/AST/Interp/Compiler.h
@@ -183,6 +183,7 @@ class Compiler : public ConstStmtVisitor, 
bool>,
   bool VisitExtVectorElementExpr(const ExtVectorElementExpr *E);
   bool VisitObjCBoxedExpr(const ObjCBoxedExpr *E);
   bool VisitCXXStdInitializerListExpr(const CXXStdInitializerListExpr *E);
+  bool VisitStmtExpr(const StmtExpr *E);
 
   // Statements.
   bool visitCompoundStmt(const CompoundStmt *S);

diff  --git a/clang/test/AST/Interp/literals.cpp 
b/clang/test/AST/Interp/literals.cpp
index ef98b4947e64f..a7a602ec355d5 100644
--- a/clang/test/AST/Interp/literals.cpp
+++ b/clang/test/AST/Interp/literals.cpp
@@ -1213,6 +1213,18 @@ constexpr int externvar1() { // both-error {{never 
produces a constant expressio
return arr[0]; // ref-note {{read of non-constexpr variable 'arr'}} \
   // expected-note {{indexing of array without known bound}}
 }
+
+namespace StmtExprs {
+  constexpr int foo() {
+ ({
+   int i;
+   for (i = 0; i < 76; i++) {}
+   i; // both-warning {{expression result unused}}
+});
+return 76;
+  }
+  static_assert(foo() == 76, "");
+}
 #endif
 
 namespace Extern {



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


[clang] [llvm] [APFloat] Add support for f8E4M3 IEEE 754 type (PR #97179)

2024-06-30 Thread Alexander Pivovarov via cfe-commits

https://github.com/apivovarov updated 
https://github.com/llvm/llvm-project/pull/97179

>From 2c5a29ebe92a8352c31e34a36ff73959ce04a557 Mon Sep 17 00:00:00 2001
From: Alexander Pivovarov 
Date: Fri, 28 Jun 2024 21:09:33 +
Subject: [PATCH] [APFloat] Add support for f8E4M3 IEEE 754 type

---
 clang/include/clang/AST/Stmt.h |  6 +--
 clang/lib/AST/MicrosoftMangle.cpp  |  1 +
 llvm/include/llvm/ADT/APFloat.h|  6 +++
 llvm/lib/Support/APFloat.cpp   | 20 +
 llvm/unittests/ADT/APFloatTest.cpp | 66 ++
 5 files changed, 96 insertions(+), 3 deletions(-)

diff --git a/clang/include/clang/AST/Stmt.h b/clang/include/clang/AST/Stmt.h
index 9cd7a364cd3f1..4edb04502f83e 100644
--- a/clang/include/clang/AST/Stmt.h
+++ b/clang/include/clang/AST/Stmt.h
@@ -460,10 +460,10 @@ class alignas(void *) Stmt {
 unsigned : NumExprBits;
 
 static_assert(
-llvm::APFloat::S_MaxSemantics < 16,
-"Too many Semantics enum values to fit in bitfield of size 4");
+llvm::APFloat::S_MaxSemantics < 32,
+"Too many Semantics enum values to fit in bitfield of size 5");
 LLVM_PREFERRED_TYPE(llvm::APFloat::Semantics)
-unsigned Semantics : 4; // Provides semantics for APFloat construction
+unsigned Semantics : 5; // Provides semantics for APFloat construction
 LLVM_PREFERRED_TYPE(bool)
 unsigned IsExact : 1;
   };
diff --git a/clang/lib/AST/MicrosoftMangle.cpp 
b/clang/lib/AST/MicrosoftMangle.cpp
index 7f1e9ab02ec26..a2e270df276cb 100644
--- a/clang/lib/AST/MicrosoftMangle.cpp
+++ b/clang/lib/AST/MicrosoftMangle.cpp
@@ -946,6 +946,7 @@ void MicrosoftCXXNameMangler::mangleFloat(llvm::APFloat 
Number) {
   case APFloat::S_IEEEquad: Out << 'Y'; break;
   case APFloat::S_PPCDoubleDouble: Out << 'Z'; break;
   case APFloat::S_Float8E5M2:
+  case APFloat::S_Float8E4M3:
   case APFloat::S_Float8E4M3FN:
   case APFloat::S_Float8E5M2FNUZ:
   case APFloat::S_Float8E4M3FNUZ:
diff --git a/llvm/include/llvm/ADT/APFloat.h b/llvm/include/llvm/ADT/APFloat.h
index db2fa480655c6..bff8e6490d1de 100644
--- a/llvm/include/llvm/ADT/APFloat.h
+++ b/llvm/include/llvm/ADT/APFloat.h
@@ -166,6 +166,9 @@ struct APFloatBase {
 // This format's exponent bias is 16, instead of the 15 (2 ** (5 - 1) - 1)
 // that IEEE precedent would imply.
 S_Float8E5M2FNUZ,
+// 8-bit floating point number following IEEE-754 conventions with bit
+// layout S1E4M3.
+S_Float8E4M3,
 // 8-bit floating point number mostly following IEEE-754 conventions with
 // bit layout S1E4M3 as described in https://arxiv.org/abs/2209.05433.
 // Unlike IEEE-754 types, there are no infinity values, and NaN is
@@ -217,6 +220,7 @@ struct APFloatBase {
   static const fltSemantics &PPCDoubleDouble() LLVM_READNONE;
   static const fltSemantics &Float8E5M2() LLVM_READNONE;
   static const fltSemantics &Float8E5M2FNUZ() LLVM_READNONE;
+  static const fltSemantics &Float8E4M3() LLVM_READNONE;
   static const fltSemantics &Float8E4M3FN() LLVM_READNONE;
   static const fltSemantics &Float8E4M3FNUZ() LLVM_READNONE;
   static const fltSemantics &Float8E4M3B11FNUZ() LLVM_READNONE;
@@ -638,6 +642,7 @@ class IEEEFloat final : public APFloatBase {
   APInt convertPPCDoubleDoubleAPFloatToAPInt() const;
   APInt convertFloat8E5M2APFloatToAPInt() const;
   APInt convertFloat8E5M2FNUZAPFloatToAPInt() const;
+  APInt convertFloat8E4M3APFloatToAPInt() const;
   APInt convertFloat8E4M3FNAPFloatToAPInt() const;
   APInt convertFloat8E4M3FNUZAPFloatToAPInt() const;
   APInt convertFloat8E4M3B11FNUZAPFloatToAPInt() const;
@@ -656,6 +661,7 @@ class IEEEFloat final : public APFloatBase {
   void initFromPPCDoubleDoubleAPInt(const APInt &api);
   void initFromFloat8E5M2APInt(const APInt &api);
   void initFromFloat8E5M2FNUZAPInt(const APInt &api);
+  void initFromFloat8E4M3APInt(const APInt &api);
   void initFromFloat8E4M3FNAPInt(const APInt &api);
   void initFromFloat8E4M3FNUZAPInt(const APInt &api);
   void initFromFloat8E4M3B11FNUZAPInt(const APInt &api);
diff --git a/llvm/lib/Support/APFloat.cpp b/llvm/lib/Support/APFloat.cpp
index 3017a9b976658..79e0094b243b2 100644
--- a/llvm/lib/Support/APFloat.cpp
+++ b/llvm/lib/Support/APFloat.cpp
@@ -136,6 +136,7 @@ static constexpr fltSemantics semIEEEquad = {16383, -16382, 
113, 128};
 static constexpr fltSemantics semFloat8E5M2 = {15, -14, 3, 8};
 static constexpr fltSemantics semFloat8E5M2FNUZ = {
 15, -15, 3, 8, fltNonfiniteBehavior::NanOnly, 
fltNanEncoding::NegativeZero};
+static constexpr fltSemantics semFloat8E4M3 = {7, -6, 4, 8};
 static constexpr fltSemantics semFloat8E4M3FN = {
 8, -6, 4, 8, fltNonfiniteBehavior::NanOnly, fltNanEncoding::AllOnes};
 static constexpr fltSemantics semFloat8E4M3FNUZ = {
@@ -208,6 +209,8 @@ const llvm::fltSemantics 
&APFloatBase::EnumToSemantics(Semantics S) {
 return Float8E5M2();
   case S_Float8E5M2FNUZ:
 return Float8E5M2FNUZ();
+  case S_Float8E4M3:
+return Float8E4M3();
   case S_Float8E4M3F

[clang] [llvm] [APFloat] Add support for f8E4M3 IEEE 754 type (PR #97179)

2024-06-30 Thread Alexander Pivovarov via cfe-commits

apivovarov wrote:

Changed commit message to "[APFloat] Add support for f8E4M3 IEEE 754 type" to 
match PR title. And Rebased

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


[clang] [llvm] [mlir] Add f8E4M3 IEEE 754 type to mlir (PR #97118)

2024-06-30 Thread Alexander Pivovarov via cfe-commits

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


[clang-tools-extra] [clang-doc] switched from using relative to absolute paths (PR #93281)

2024-06-30 Thread via cfe-commits

https://github.com/PeterChou1 updated 
https://github.com/llvm/llvm-project/pull/93281

>From f5872e7c82d097ae3c141765d3f1d7e3d0b25b82 Mon Sep 17 00:00:00 2001
From: PeterChou1 
Date: Fri, 24 May 2024 04:28:08 -0400
Subject: [PATCH 1/8] clang-doc switched from using relative to absolute paths

---
 clang-tools-extra/clang-doc/assets/index.js | 72 ++---
 1 file changed, 35 insertions(+), 37 deletions(-)

diff --git a/clang-tools-extra/clang-doc/assets/index.js 
b/clang-tools-extra/clang-doc/assets/index.js
index a5ac90f2e06e7..fe35e706cc98d 100644
--- a/clang-tools-extra/clang-doc/assets/index.js
+++ b/clang-tools-extra/clang-doc/assets/index.js
@@ -1,48 +1,46 @@
-// Append using posix-style a file name or directory to Base
-function append(Base, New) {
-  if (!New)
-return Base;
-  if (Base)
-Base += "/";
-  Base += New;
-  return Base;
-}
-
-// Get relative path to access FilePath from CurrentDirectory
-function computeRelativePath(FilePath, CurrentDirectory) {
-  var Path = FilePath;
-  while (Path) {
-if (CurrentDirectory == Path)
-  return FilePath.substring(Path.length + 1);
-Path = Path.substring(0, Path.lastIndexOf("/"));
-  }
-
-  var Dir = CurrentDirectory;
-  var Result = "";
-  while (Dir) {
-if (Dir == FilePath)
-  break;
-Dir = Dir.substring(0, Dir.lastIndexOf("/"));
-Result = append(Result, "..")
+function genLink(Ref) {
+  var Path = 
`${window.location.protocol}//${window.location.host}/${Ref.Path}`;
+  if (Ref.RefType !== "namespace") {
+if (Ref.Path === "") {
+  Path = `${Path}${Ref.Name}.html`;
+}
+else {
+  Path = `${Path}/${Ref.Name}.html`;
+}
   }
-  Result = append(Result, FilePath.substring(Dir.length))
-  return Result;
-}
-
-function genLink(Ref, CurrentDirectory) {
-  var Path = computeRelativePath(Ref.Path, CurrentDirectory);
-  if (Ref.RefType == "namespace")
-Path = append(Path, "index.html");
-  else
-Path = append(Path, Ref.Name + ".html")
 
-ANode = document.createElement("a");
+  ANode = document.createElement("a");
   ANode.setAttribute("href", Path);
   var TextNode = document.createTextNode(Ref.Name);
   ANode.appendChild(TextNode);
   return ANode;
 }
 
+function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) {
+  // Out will store the HTML elements that Index requires to be generated
+  var Out = [];
+  if (Index.Name) {
+var SpanNode = document.createElement("span");
+var TextNode = document.createTextNode(Index.Name);
+SpanNode.appendChild(genLink(Index));
+Out.push(SpanNode);
+  }
+  if (Index.Children.length == 0)
+return Out;
+  // Only the outermost list should use ol, the others should use ul
+  var ListNodeName = IsOutermostList ? "ol" : "ul";
+  var ListNode = document.createElement(ListNodeName);
+  for (Child of Index.Children) {
+var LiNode = document.createElement("li");
+ChildNodes = genHTMLOfIndex(Child, CurrentDirectory, false);
+for (Node of ChildNodes)
+  LiNode.appendChild(Node);
+ListNode.appendChild(LiNode);
+  }
+  Out.push(ListNode);
+  return Out;
+}
+
 function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) {
   // Out will store the HTML elements that Index requires to be generated
   var Out = [];

>From a22609f75064194604e476a12bc8154676dacfb9 Mon Sep 17 00:00:00 2001
From: PeterChou1 
Date: Fri, 24 May 2024 05:10:03 -0400
Subject: [PATCH 2/8] remove duplicate function

---
 clang-tools-extra/clang-doc/assets/index.js | 24 -
 1 file changed, 24 deletions(-)

diff --git a/clang-tools-extra/clang-doc/assets/index.js 
b/clang-tools-extra/clang-doc/assets/index.js
index fe35e706cc98d..b013418c82093 100644
--- a/clang-tools-extra/clang-doc/assets/index.js
+++ b/clang-tools-extra/clang-doc/assets/index.js
@@ -16,30 +16,6 @@ function genLink(Ref) {
   return ANode;
 }
 
-function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) {
-  // Out will store the HTML elements that Index requires to be generated
-  var Out = [];
-  if (Index.Name) {
-var SpanNode = document.createElement("span");
-var TextNode = document.createTextNode(Index.Name);
-SpanNode.appendChild(genLink(Index));
-Out.push(SpanNode);
-  }
-  if (Index.Children.length == 0)
-return Out;
-  // Only the outermost list should use ol, the others should use ul
-  var ListNodeName = IsOutermostList ? "ol" : "ul";
-  var ListNode = document.createElement(ListNodeName);
-  for (Child of Index.Children) {
-var LiNode = document.createElement("li");
-ChildNodes = genHTMLOfIndex(Child, CurrentDirectory, false);
-for (Node of ChildNodes)
-  LiNode.appendChild(Node);
-ListNode.appendChild(LiNode);
-  }
-  Out.push(ListNode);
-  return Out;
-}
 
 function genHTMLOfIndex(Index, CurrentDirectory, IsOutermostList) {
   // Out will store the HTML elements that Index requires to be generated

>From be0fb1acdd97a07e665b61fbba44d32dd40e1b94 Mon Sep 17 00:00:00 2001
From: PeterChou1 
Date: Sa

[clang] [llvm] [APFloat] Add support for f8E4M3 IEEE 754 type (PR #97179)

2024-06-30 Thread Thorsten Schütt via cfe-commits


@@ -136,6 +136,7 @@ static constexpr fltSemantics semIEEEquad = {16383, -16382, 
113, 128};
 static constexpr fltSemantics semFloat8E5M2 = {15, -14, 3, 8};
 static constexpr fltSemantics semFloat8E5M2FNUZ = {
 15, -15, 3, 8, fltNonfiniteBehavior::NanOnly, 
fltNanEncoding::NegativeZero};
+static constexpr fltSemantics semFloat8E4M3 = {7, -6, 4, 8};

tschuett wrote:

Just checking that you want default semantics?

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


[clang] [llvm] [RISCV] Add support for getHostCPUFeatures using hwprobe (PR #94352)

2024-06-30 Thread Yingwei Zheng via cfe-commits


@@ -290,8 +290,24 @@ StringRef riscv::getRISCVArch(const llvm::opt::ArgList 
&Args,
   // 2. Get march (isa string) based on `-mcpu=`
   if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) {
 StringRef CPU = A->getValue();
-if (CPU == "native")
+if (CPU == "native") {
   CPU = llvm::sys::getHostCPUName();
+  // If the target cpu is unrecognized, use target features.
+  if (CPU.empty() || CPU.starts_with("generic")) {
+llvm::StringMap HostFeatures;
+if (llvm::sys::getHostCPUFeatures(HostFeatures)) {
+  std::vector Features;
+  for (auto &F : HostFeatures)
+Features.push_back(
+Args.MakeArgString((F.second ? "+" : "-") + F.first()));
+
+  auto ParseResult = llvm::RISCVISAInfo::parseFeatures(
+  Triple.isRISCV32() ? 32 : 64, Features);
+  if (ParseResult)
+return (*ParseResult)->toString();

dtcxzyw wrote:

@preames Do you think it is ok to change the return type of 
`riscv::getRISCVArch` to `std::string`?


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


[clang] RFC: [cmake] Export CLANG_RESOURCE_DIR in ClangConfig (PR #97197)

2024-06-30 Thread Kim Gräsman via cfe-commits

https://github.com/kimgr created https://github.com/llvm/llvm-project/pull/97197

I recently opened #95747 to see if it would be advisable to expose 
`CLANG_RESOURCE_DIR` from `ClangConfig.cmake`.

Here's a patch to do the most naive thing I could think of, hopefully enough to 
trigger discussion.

Open questions/concerns:

* `ClangConfig.cmake` now defines `CLANG_RESOURCE_DIR` -- will that interfere 
with the CMake system's `CLANG_RESOURCE_DIR` (which is e.g. baked into config.h)
* The builddir vs. installdir distinction when generate `ClangConfig.cmake` 
isn't 100% clear to me, I guessed a little as to reasonable prefix paths


From 90c3f251342c7452b6d3efc44bb976fc5abc81e4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Kim=20Gr=C3=A4sman?= 
Date: Sun, 30 Jun 2024 10:45:24 +0200
Subject: [PATCH] RFC: [cmake] Export CLANG_RESOURCE_DIR in ClangConfig

---
 clang/cmake/modules/CMakeLists.txt   | 9 +
 clang/cmake/modules/ClangConfig.cmake.in | 1 +
 2 files changed, 10 insertions(+)

diff --git a/clang/cmake/modules/CMakeLists.txt 
b/clang/cmake/modules/CMakeLists.txt
index d2d68121371bf..4b0a38bd0fc1e 100644
--- a/clang/cmake/modules/CMakeLists.txt
+++ b/clang/cmake/modules/CMakeLists.txt
@@ -2,6 +2,7 @@ include(GNUInstallPackageDir)
 include(ExtendPath)
 include(LLVMDistributionSupport)
 include(FindPrefixFromConfig)
+include(GetClangResourceDir)
 
 # Generate a list of CMake library targets so that other CMake projects can
 # link against them. LLVM calls its version of this file LLVMExports.cmake, but
@@ -29,6 +30,10 @@ set(CLANG_CONFIG_INCLUDE_DIRS
   "${CLANG_SOURCE_DIR}/include"
   "${CLANG_BINARY_DIR}/include"
   )
+
+get_clang_resource_dir(resource_builddir PREFIX ${CLANG_BINARY_DIR})
+set(CLANG_CONFIG_RESOURCE_DIR ${resource_builddir})
+
 configure_file(
   ${CMAKE_CURRENT_SOURCE_DIR}/ClangConfig.cmake.in
   ${clang_cmake_builddir}/ClangConfig.cmake
@@ -60,6 +65,10 @@ extend_path(base_includedir "\${CLANG_INSTALL_PREFIX}" 
"${CMAKE_INSTALL_INCLUDED
 set(CLANG_CONFIG_INCLUDE_DIRS
   "${base_includedir}"
   )
+
+get_clang_resource_dir(resource_installdir PREFIX ${CLANG_INSTALL_PREFIX})
+set(CLANG_CONFIG_RESOURCE_DIR "${resource_installdir}")
+
 configure_file(
   ${CMAKE_CURRENT_SOURCE_DIR}/ClangConfig.cmake.in
   ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/ClangConfig.cmake
diff --git a/clang/cmake/modules/ClangConfig.cmake.in 
b/clang/cmake/modules/ClangConfig.cmake.in
index 5f67681649c66..1b97e103c93ca 100644
--- a/clang/cmake/modules/ClangConfig.cmake.in
+++ b/clang/cmake/modules/ClangConfig.cmake.in
@@ -10,6 +10,7 @@ set(CLANG_EXPORTED_TARGETS "@CLANG_EXPORTS@")
 set(CLANG_CMAKE_DIR "@CLANG_CONFIG_CMAKE_DIR@")
 set(CLANG_INCLUDE_DIRS "@CLANG_CONFIG_INCLUDE_DIRS@")
 set(CLANG_LINK_CLANG_DYLIB "@CLANG_LINK_CLANG_DYLIB@")
+set(CLANG_RESOURCE_DIR "@CLANG_CONFIG_RESOURCE_DIR@")
 
 # Provide all our library targets to users.
 @CLANG_CONFIG_INCLUDE_EXPORTS@

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


[clang] RFC: [cmake] Export CLANG_RESOURCE_DIR in ClangConfig (PR #97197)

2024-06-30 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Kim Gräsman (kimgr)


Changes

I recently opened #95747 to see if it would be advisable to expose 
`CLANG_RESOURCE_DIR` from `ClangConfig.cmake`.

Here's a patch to do the most naive thing I could think of, hopefully enough to 
trigger discussion.

Open questions/concerns:

* `ClangConfig.cmake` now defines `CLANG_RESOURCE_DIR` -- will that interfere 
with the CMake system's `CLANG_RESOURCE_DIR` (which is e.g. baked into config.h)
* The builddir vs. installdir distinction when generate `ClangConfig.cmake` 
isn't 100% clear to me, I guessed a little as to reasonable prefix paths


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


2 Files Affected:

- (modified) clang/cmake/modules/CMakeLists.txt (+9) 
- (modified) clang/cmake/modules/ClangConfig.cmake.in (+1) 


``diff
diff --git a/clang/cmake/modules/CMakeLists.txt 
b/clang/cmake/modules/CMakeLists.txt
index d2d68121371bf..4b0a38bd0fc1e 100644
--- a/clang/cmake/modules/CMakeLists.txt
+++ b/clang/cmake/modules/CMakeLists.txt
@@ -2,6 +2,7 @@ include(GNUInstallPackageDir)
 include(ExtendPath)
 include(LLVMDistributionSupport)
 include(FindPrefixFromConfig)
+include(GetClangResourceDir)
 
 # Generate a list of CMake library targets so that other CMake projects can
 # link against them. LLVM calls its version of this file LLVMExports.cmake, but
@@ -29,6 +30,10 @@ set(CLANG_CONFIG_INCLUDE_DIRS
   "${CLANG_SOURCE_DIR}/include"
   "${CLANG_BINARY_DIR}/include"
   )
+
+get_clang_resource_dir(resource_builddir PREFIX ${CLANG_BINARY_DIR})
+set(CLANG_CONFIG_RESOURCE_DIR ${resource_builddir})
+
 configure_file(
   ${CMAKE_CURRENT_SOURCE_DIR}/ClangConfig.cmake.in
   ${clang_cmake_builddir}/ClangConfig.cmake
@@ -60,6 +65,10 @@ extend_path(base_includedir "\${CLANG_INSTALL_PREFIX}" 
"${CMAKE_INSTALL_INCLUDED
 set(CLANG_CONFIG_INCLUDE_DIRS
   "${base_includedir}"
   )
+
+get_clang_resource_dir(resource_installdir PREFIX ${CLANG_INSTALL_PREFIX})
+set(CLANG_CONFIG_RESOURCE_DIR "${resource_installdir}")
+
 configure_file(
   ${CMAKE_CURRENT_SOURCE_DIR}/ClangConfig.cmake.in
   ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/ClangConfig.cmake
diff --git a/clang/cmake/modules/ClangConfig.cmake.in 
b/clang/cmake/modules/ClangConfig.cmake.in
index 5f67681649c66..1b97e103c93ca 100644
--- a/clang/cmake/modules/ClangConfig.cmake.in
+++ b/clang/cmake/modules/ClangConfig.cmake.in
@@ -10,6 +10,7 @@ set(CLANG_EXPORTED_TARGETS "@CLANG_EXPORTS@")
 set(CLANG_CMAKE_DIR "@CLANG_CONFIG_CMAKE_DIR@")
 set(CLANG_INCLUDE_DIRS "@CLANG_CONFIG_INCLUDE_DIRS@")
 set(CLANG_LINK_CLANG_DYLIB "@CLANG_LINK_CLANG_DYLIB@")
+set(CLANG_RESOURCE_DIR "@CLANG_CONFIG_RESOURCE_DIR@")
 
 # Provide all our library targets to users.
 @CLANG_CONFIG_INCLUDE_EXPORTS@

``




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


[clang] RFC: [cmake] Export CLANG_RESOURCE_DIR in ClangConfig (PR #97197)

2024-06-30 Thread Kim Gräsman via cfe-commits

kimgr wrote:

cc @llvm-beanz -- you seem to have done a fair bit with the LLVM CMake system.

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


[clang] [analyzer] Fix crash in Stream checker when using void pointers (PR #97199)

2024-06-30 Thread Balazs Benics via cfe-commits

https://github.com/steakhal created 
https://github.com/llvm/llvm-project/pull/97199

We can get zero type size (thus div by zero crash) if the region is for a 
'void*' pointer.
In this patch, let's just override the void type with a char type to avoid the 
crash.

Fixes
https://github.com/llvm/llvm-project/pull/93408#issuecomment-2189766510

>From 81910b6d8139868304c87784416e087e2aea9f7a Mon Sep 17 00:00:00 2001
From: Balazs Benics 
Date: Sun, 30 Jun 2024 11:32:14 +0200
Subject: [PATCH] [analyzer] Fix crash in Stream checker when using void
 pointers

We can get zero type size (thus div by zero crash) if the region is for
a 'void*' pointer.
In this patch, let's just override the void type with a char type to
avoid the crash.

Fixes
https://github.com/llvm/llvm-project/pull/93408#issuecomment-2189766510
---
 .../StaticAnalyzer/Checkers/StreamChecker.cpp | 39 ---
 clang/test/Analysis/stream.c  | 13 +++
 2 files changed, 38 insertions(+), 14 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
index 9aee7f952ad2d..0d1d50d19f4c4 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -1034,16 +1034,19 @@ void StreamChecker::preWrite(const FnDescription *Desc, 
const CallEvent &Call,
   C.addTransition(State);
 }
 
-static std::optional getPointeeType(const MemRegion *R) {
+static QualType getPointeeType(const MemRegion *R) {
   if (!R)
-return std::nullopt;
-  if (const auto *ER = dyn_cast(R))
-return ER->getElementType();
-  if (const auto *TR = dyn_cast(R))
-return TR->getValueType();
-  if (const auto *SR = dyn_cast(R))
-return SR->getPointeeStaticType();
-  return std::nullopt;
+return {};
+  QualType Ty = [R] {
+if (const auto *ER = dyn_cast(R))
+  return ER->getElementType();
+if (const auto *TR = dyn_cast(R))
+  return TR->getValueType();
+if (const auto *SR = dyn_cast(R))
+  return SR->getPointeeStaticType();
+return QualType{};
+  }();
+  return !Ty.isNull() ? Ty->getCanonicalTypeUnqualified() : QualType{};
 }
 
 static std::optional getStartIndex(SValBuilder &SVB,
@@ -1073,7 +1076,16 @@ tryToInvalidateFReadBufferByElements(ProgramStateRef 
State, CheckerContext &C,
   const auto *Buffer =
   dyn_cast_or_null(Call.getArgSVal(0).getAsRegion());
 
-  std::optional ElemTy = getPointeeType(Buffer);
+  const ASTContext &Ctx = C.getASTContext();
+
+  QualType ElemTy = getPointeeType(Buffer);
+
+  // Consider pointer to void as a pointer to char buffer such that it has a
+  // non-zero type size.
+  if (!ElemTy.isNull() && ElemTy == Ctx.VoidTy) {
+ElemTy = Ctx.CharTy;
+  }
+
   std::optional StartElementIndex =
   getStartIndex(C.getSValBuilder(), Buffer);
 
@@ -1086,10 +1098,9 @@ tryToInvalidateFReadBufferByElements(ProgramStateRef 
State, CheckerContext &C,
   std::optional StartIndexVal =
   getKnownValue(State, StartElementIndex.value_or(UnknownVal()));
 
-  if (ElemTy && CountVal && Size && StartIndexVal) {
+  if (!ElemTy.isNull() && CountVal && Size && StartIndexVal) {
 int64_t NumBytesRead = Size.value() * CountVal.value();
-int64_t ElemSizeInChars =
-C.getASTContext().getTypeSizeInChars(*ElemTy).getQuantity();
+int64_t ElemSizeInChars = Ctx.getTypeSizeInChars(ElemTy).getQuantity();
 bool IncompleteLastElement = (NumBytesRead % ElemSizeInChars) != 0;
 int64_t NumCompleteOrIncompleteElementsRead =
 NumBytesRead / ElemSizeInChars + IncompleteLastElement;
@@ -1097,7 +1108,7 @@ tryToInvalidateFReadBufferByElements(ProgramStateRef 
State, CheckerContext &C,
 constexpr int MaxInvalidatedElementsLimit = 64;
 if (NumCompleteOrIncompleteElementsRead <= MaxInvalidatedElementsLimit) {
   return escapeByStartIndexAndCount(State, Call, C.blockCount(), Buffer,
-*ElemTy, *StartIndexVal,
+ElemTy, *StartIndexVal,
 NumCompleteOrIncompleteElementsRead);
 }
   }
diff --git a/clang/test/Analysis/stream.c b/clang/test/Analysis/stream.c
index db03d90cd8af4..0869b1b325172 100644
--- a/clang/test/Analysis/stream.c
+++ b/clang/test/Analysis/stream.c
@@ -453,3 +453,16 @@ void getline_buffer_size_negative() {
   free(buffer);
   fclose(file);
 }
+
+void gh_93408_regression(void *buffer) {
+  FILE *f = fopen("/tmp/foo.txt", "r");
+  fread(buffer, 1, 1, f); // expected-warning {{Stream pointer might be NULL}} 
no-crash: void is treated as char.
+  fclose(f);
+}
+
+typedef void VOID;
+void gh_93408_regression_typedef(VOID *buffer) {
+  FILE *f = fopen("/tmp/foo.txt", "r");
+  fread(buffer, 1, 1, f); // expected-warning {{Stream pointer might be NULL}} 
no-crash: VOID is treated as char.
+  fclose(f);
+}

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://list

[clang] [analyzer] Fix crash in Stream checker when using void pointers (PR #97199)

2024-06-30 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-static-analyzer-1

Author: Balazs Benics (steakhal)


Changes

We can get zero type size (thus div by zero crash) if the region is for a 
'void*' pointer.
In this patch, let's just override the void type with a char type to avoid the 
crash.

Fixes
https://github.com/llvm/llvm-project/pull/93408#issuecomment-2189766510

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


2 Files Affected:

- (modified) clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp (+25-14) 
- (modified) clang/test/Analysis/stream.c (+13) 


``diff
diff --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
index 9aee7f952ad2d..0d1d50d19f4c4 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -1034,16 +1034,19 @@ void StreamChecker::preWrite(const FnDescription *Desc, 
const CallEvent &Call,
   C.addTransition(State);
 }
 
-static std::optional getPointeeType(const MemRegion *R) {
+static QualType getPointeeType(const MemRegion *R) {
   if (!R)
-return std::nullopt;
-  if (const auto *ER = dyn_cast(R))
-return ER->getElementType();
-  if (const auto *TR = dyn_cast(R))
-return TR->getValueType();
-  if (const auto *SR = dyn_cast(R))
-return SR->getPointeeStaticType();
-  return std::nullopt;
+return {};
+  QualType Ty = [R] {
+if (const auto *ER = dyn_cast(R))
+  return ER->getElementType();
+if (const auto *TR = dyn_cast(R))
+  return TR->getValueType();
+if (const auto *SR = dyn_cast(R))
+  return SR->getPointeeStaticType();
+return QualType{};
+  }();
+  return !Ty.isNull() ? Ty->getCanonicalTypeUnqualified() : QualType{};
 }
 
 static std::optional getStartIndex(SValBuilder &SVB,
@@ -1073,7 +1076,16 @@ tryToInvalidateFReadBufferByElements(ProgramStateRef 
State, CheckerContext &C,
   const auto *Buffer =
   dyn_cast_or_null(Call.getArgSVal(0).getAsRegion());
 
-  std::optional ElemTy = getPointeeType(Buffer);
+  const ASTContext &Ctx = C.getASTContext();
+
+  QualType ElemTy = getPointeeType(Buffer);
+
+  // Consider pointer to void as a pointer to char buffer such that it has a
+  // non-zero type size.
+  if (!ElemTy.isNull() && ElemTy == Ctx.VoidTy) {
+ElemTy = Ctx.CharTy;
+  }
+
   std::optional StartElementIndex =
   getStartIndex(C.getSValBuilder(), Buffer);
 
@@ -1086,10 +1098,9 @@ tryToInvalidateFReadBufferByElements(ProgramStateRef 
State, CheckerContext &C,
   std::optional StartIndexVal =
   getKnownValue(State, StartElementIndex.value_or(UnknownVal()));
 
-  if (ElemTy && CountVal && Size && StartIndexVal) {
+  if (!ElemTy.isNull() && CountVal && Size && StartIndexVal) {
 int64_t NumBytesRead = Size.value() * CountVal.value();
-int64_t ElemSizeInChars =
-C.getASTContext().getTypeSizeInChars(*ElemTy).getQuantity();
+int64_t ElemSizeInChars = Ctx.getTypeSizeInChars(ElemTy).getQuantity();
 bool IncompleteLastElement = (NumBytesRead % ElemSizeInChars) != 0;
 int64_t NumCompleteOrIncompleteElementsRead =
 NumBytesRead / ElemSizeInChars + IncompleteLastElement;
@@ -1097,7 +1108,7 @@ tryToInvalidateFReadBufferByElements(ProgramStateRef 
State, CheckerContext &C,
 constexpr int MaxInvalidatedElementsLimit = 64;
 if (NumCompleteOrIncompleteElementsRead <= MaxInvalidatedElementsLimit) {
   return escapeByStartIndexAndCount(State, Call, C.blockCount(), Buffer,
-*ElemTy, *StartIndexVal,
+ElemTy, *StartIndexVal,
 NumCompleteOrIncompleteElementsRead);
 }
   }
diff --git a/clang/test/Analysis/stream.c b/clang/test/Analysis/stream.c
index db03d90cd8af4..0869b1b325172 100644
--- a/clang/test/Analysis/stream.c
+++ b/clang/test/Analysis/stream.c
@@ -453,3 +453,16 @@ void getline_buffer_size_negative() {
   free(buffer);
   fclose(file);
 }
+
+void gh_93408_regression(void *buffer) {
+  FILE *f = fopen("/tmp/foo.txt", "r");
+  fread(buffer, 1, 1, f); // expected-warning {{Stream pointer might be NULL}} 
no-crash: void is treated as char.
+  fclose(f);
+}
+
+typedef void VOID;
+void gh_93408_regression_typedef(VOID *buffer) {
+  FILE *f = fopen("/tmp/foo.txt", "r");
+  fread(buffer, 1, 1, f); // expected-warning {{Stream pointer might be NULL}} 
no-crash: VOID is treated as char.
+  fclose(f);
+}

``




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


[clang] [NFC] [Clang] Some core issues have changed status from tentatively ready -> ready / review (PR #97200)

2024-06-30 Thread Mital Ashok via cfe-commits

https://github.com/MitalAshok created 
https://github.com/llvm/llvm-project/pull/97200

Also classes the "ready" status similarly to "tentatively ready" in 
make_cxx_dr_status


>From 0dea95701ca4dfca9b7d0bd889003fc35aa3017e Mon Sep 17 00:00:00 2001
From: Mital Ashok 
Date: Sun, 30 Jun 2024 10:39:15 +0100
Subject: [PATCH] [NFC] [Clang] Some core issues have changed status from
 tentatively ready -> ready / review

---
 clang/test/CXX/drs/cwg25xx.cpp |   2 +-
 clang/test/CXX/drs/cwg28xx.cpp |  16 ++--
 clang/www/cxx_dr_status.html   | 130 +++--
 clang/www/make_cxx_dr_status   |   6 +-
 4 files changed, 104 insertions(+), 50 deletions(-)

diff --git a/clang/test/CXX/drs/cwg25xx.cpp b/clang/test/CXX/drs/cwg25xx.cpp
index 0934f0cc19c6a..5f8a058f8157a 100644
--- a/clang/test/CXX/drs/cwg25xx.cpp
+++ b/clang/test/CXX/drs/cwg25xx.cpp
@@ -139,7 +139,7 @@ struct D3 : B {
 #endif
 
 #if __cplusplus >= 202302L
-namespace cwg2561 { // cwg2561: no tentatively ready 2024-03-18
+namespace cwg2561 { // cwg2561: no ready 2024-03-18
 struct C {
 constexpr C(auto) { }
 };
diff --git a/clang/test/CXX/drs/cwg28xx.cpp b/clang/test/CXX/drs/cwg28xx.cpp
index c77bd433d8e21..524e67b52de51 100644
--- a/clang/test/CXX/drs/cwg28xx.cpp
+++ b/clang/test/CXX/drs/cwg28xx.cpp
@@ -30,7 +30,7 @@ using U2 = decltype(&main);
 #endif
 } // namespace cwg2811
 
-namespace cwg2819 { // cwg2819: 19 tentatively ready 2023-12-01
+namespace cwg2819 { // cwg2819: 19 ready 2023-12-01
 #if __cpp_constexpr >= 202306L
   constexpr void* p = nullptr;
   constexpr int* q = static_cast(p);
@@ -111,7 +111,7 @@ struct D : N::B {
 #endif
 } // namespace cwg2857
 
-namespace cwg2858 { // cwg2858: 19 tentatively ready 2024-04-05
+namespace cwg2858 { // cwg2858: 19 ready 2024-04-05
 
 #if __cplusplus > 202302L
 
@@ -134,7 +134,7 @@ struct A {
 
 } // namespace cwg2858
 
-namespace cwg2877 { // cwg2877: 19 tentatively ready 2024-05-31
+namespace cwg2877 { // cwg2877: 19 ready 2024-05-31
 #if __cplusplus >= 202002L
 enum E { x };
 void f() {
@@ -150,7 +150,7 @@ void g() {
 #endif
 } // namespace cwg2877
 
-namespace cwg2881 { // cwg2881: 19 tentatively ready 2024-04-19
+namespace cwg2881 { // cwg2881: 19 ready 2024-04-19
 
 #if __cplusplus >= 202302L
 
@@ -220,7 +220,7 @@ void f() {
 
 } // namespace cwg2881
 
-namespace cwg2882 { // cwg2882: 2.7 tentatively ready 2024-05-31
+namespace cwg2882 { // cwg2882: 2.7 ready 2024-05-31
 struct C {
   operator void() = delete;
   // expected-warning@-1 {{conversion function converting 'cwg2882::C' to 
'void' will never be used}}
@@ -232,7 +232,7 @@ void f(C c) {
 }
 } // namespace cwg2882
 
-namespace cwg2883 { // cwg2883: no tentatively ready 2024-05-31
+namespace cwg2883 { // cwg2883: no ready 2024-05-31
 #if __cplusplus >= 201103L
 void f() {
   int x;
@@ -257,7 +257,7 @@ void g() {
 #endif
 } // namespace cwg2883
 
-namespace cwg2885 { // cwg2885: 16 tentatively ready 2024-05-31
+namespace cwg2885 { // cwg2885: 16 review 2024-05-31
 #if __cplusplus >= 202002L
 template 
 struct A {
@@ -271,7 +271,7 @@ static_assert(!__is_trivially_constructible(B));
 #endif
 } // namespace cwg2885
 
-namespace cwg2886 { // cwg2886: 9 tentatively ready 2024-05-31
+namespace cwg2886 { // cwg2886: 9 ready 2024-05-31
 #if __cplusplus >= 201103L
 struct C {
   C() = default;
diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index 937f67981e296..64b361976a5a5 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -1442,7 +1442,7 @@ C++ defect report implementation 
status
   
   
 https://cplusplus.github.io/CWG/issues/233.html";>233
-tentatively ready
+ready
 References vs pointers in UDC overload resolution
 Not resolved
   
@@ -7329,11 +7329,11 @@ C++ defect report implementation 
status
 Overloading member function templates based on dependent return 
type
 Unknown
   
-  
+  
 https://cplusplus.github.io/CWG/issues/1253.html";>1253
-open
+C++17
 Generic non-template members
-Not resolved
+Unknown
   
   
 https://cplusplus.github.io/CWG/issues/1254.html";>1254
@@ -12677,7 +12677,7 @@ C++ defect report implementation 
status
   
   
 https://cplusplus.github.io/CWG/issues/2144.html";>2144
-tentatively ready
+ready
 Function/variable declaration ambiguity
 Not resolved
   
@@ -15179,7 +15179,7 @@ C++ defect report implementation 
status
   
   
 https://cplusplus.github.io/CWG/issues/2561.html";>2561
-tentatively ready
+ready
 Conversion to function pointer for lambda with explicit object 
parameter
 Not Resolved*
   
@@ -15341,7 +15341,7 @@ C++ defect report implementation 
status
   
   
 https://cplusplus.github.io/CWG/issues/2588.html";>2588
-tentatively ready
+ready
 friend declarations and module linkage
 Not resolved
   
@@ -15541,7 +15541,7 @@ C++ defect report implementation 
status
 https://cplusplus.github.io/CWG/issues/2621.html";>26

[clang] [NFC] [Clang] Some core issues have changed status from tentatively ready -> ready / review (PR #97200)

2024-06-30 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Mital Ashok (MitalAshok)


Changes

Also classes the "ready" status similarly to "tentatively ready" in 
make_cxx_dr_status


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


4 Files Affected:

- (modified) clang/test/CXX/drs/cwg25xx.cpp (+1-1) 
- (modified) clang/test/CXX/drs/cwg28xx.cpp (+8-8) 
- (modified) clang/www/cxx_dr_status.html (+92-38) 
- (modified) clang/www/make_cxx_dr_status (+3-3) 


``diff
diff --git a/clang/test/CXX/drs/cwg25xx.cpp b/clang/test/CXX/drs/cwg25xx.cpp
index 0934f0cc19c6a..5f8a058f8157a 100644
--- a/clang/test/CXX/drs/cwg25xx.cpp
+++ b/clang/test/CXX/drs/cwg25xx.cpp
@@ -139,7 +139,7 @@ struct D3 : B {
 #endif
 
 #if __cplusplus >= 202302L
-namespace cwg2561 { // cwg2561: no tentatively ready 2024-03-18
+namespace cwg2561 { // cwg2561: no ready 2024-03-18
 struct C {
 constexpr C(auto) { }
 };
diff --git a/clang/test/CXX/drs/cwg28xx.cpp b/clang/test/CXX/drs/cwg28xx.cpp
index c77bd433d8e21..524e67b52de51 100644
--- a/clang/test/CXX/drs/cwg28xx.cpp
+++ b/clang/test/CXX/drs/cwg28xx.cpp
@@ -30,7 +30,7 @@ using U2 = decltype(&main);
 #endif
 } // namespace cwg2811
 
-namespace cwg2819 { // cwg2819: 19 tentatively ready 2023-12-01
+namespace cwg2819 { // cwg2819: 19 ready 2023-12-01
 #if __cpp_constexpr >= 202306L
   constexpr void* p = nullptr;
   constexpr int* q = static_cast(p);
@@ -111,7 +111,7 @@ struct D : N::B {
 #endif
 } // namespace cwg2857
 
-namespace cwg2858 { // cwg2858: 19 tentatively ready 2024-04-05
+namespace cwg2858 { // cwg2858: 19 ready 2024-04-05
 
 #if __cplusplus > 202302L
 
@@ -134,7 +134,7 @@ struct A {
 
 } // namespace cwg2858
 
-namespace cwg2877 { // cwg2877: 19 tentatively ready 2024-05-31
+namespace cwg2877 { // cwg2877: 19 ready 2024-05-31
 #if __cplusplus >= 202002L
 enum E { x };
 void f() {
@@ -150,7 +150,7 @@ void g() {
 #endif
 } // namespace cwg2877
 
-namespace cwg2881 { // cwg2881: 19 tentatively ready 2024-04-19
+namespace cwg2881 { // cwg2881: 19 ready 2024-04-19
 
 #if __cplusplus >= 202302L
 
@@ -220,7 +220,7 @@ void f() {
 
 } // namespace cwg2881
 
-namespace cwg2882 { // cwg2882: 2.7 tentatively ready 2024-05-31
+namespace cwg2882 { // cwg2882: 2.7 ready 2024-05-31
 struct C {
   operator void() = delete;
   // expected-warning@-1 {{conversion function converting 'cwg2882::C' to 
'void' will never be used}}
@@ -232,7 +232,7 @@ void f(C c) {
 }
 } // namespace cwg2882
 
-namespace cwg2883 { // cwg2883: no tentatively ready 2024-05-31
+namespace cwg2883 { // cwg2883: no ready 2024-05-31
 #if __cplusplus >= 201103L
 void f() {
   int x;
@@ -257,7 +257,7 @@ void g() {
 #endif
 } // namespace cwg2883
 
-namespace cwg2885 { // cwg2885: 16 tentatively ready 2024-05-31
+namespace cwg2885 { // cwg2885: 16 review 2024-05-31
 #if __cplusplus >= 202002L
 template 
 struct A {
@@ -271,7 +271,7 @@ static_assert(!__is_trivially_constructible(B));
 #endif
 } // namespace cwg2885
 
-namespace cwg2886 { // cwg2886: 9 tentatively ready 2024-05-31
+namespace cwg2886 { // cwg2886: 9 ready 2024-05-31
 #if __cplusplus >= 201103L
 struct C {
   C() = default;
diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index 937f67981e296..64b361976a5a5 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -1442,7 +1442,7 @@ C++ defect report implementation 
status
   
   
 https://cplusplus.github.io/CWG/issues/233.html";>233
-tentatively ready
+ready
 References vs pointers in UDC overload resolution
 Not resolved
   
@@ -7329,11 +7329,11 @@ C++ defect report implementation 
status
 Overloading member function templates based on dependent return 
type
 Unknown
   
-  
+  
 https://cplusplus.github.io/CWG/issues/1253.html";>1253
-open
+C++17
 Generic non-template members
-Not resolved
+Unknown
   
   
 https://cplusplus.github.io/CWG/issues/1254.html";>1254
@@ -12677,7 +12677,7 @@ C++ defect report implementation 
status
   
   
 https://cplusplus.github.io/CWG/issues/2144.html";>2144
-tentatively ready
+ready
 Function/variable declaration ambiguity
 Not resolved
   
@@ -15179,7 +15179,7 @@ C++ defect report implementation 
status
   
   
 https://cplusplus.github.io/CWG/issues/2561.html";>2561
-tentatively ready
+ready
 Conversion to function pointer for lambda with explicit object 
parameter
 Not Resolved*
   
@@ -15341,7 +15341,7 @@ C++ defect report implementation 
status
   
   
 https://cplusplus.github.io/CWG/issues/2588.html";>2588
-tentatively ready
+ready
 friend declarations and module linkage
 Not resolved
   
@@ -15541,7 +15541,7 @@ C++ defect report implementation 
status
 https://cplusplus.github.io/CWG/issues/2621.html";>2621
 C++23
 Kind of lookup for using enum declarations
-Superseded by 2877
+Superseded by 2877
   
   
 https://cplusplus.github.io/CWG/issues/2622.html";>2622
@

[clang] [NFC] [Clang] Some core issues have changed status from tentatively ready -> ready / review (PR #97200)

2024-06-30 Thread Vlad Serebrennikov via cfe-commits


@@ -150,7 +150,7 @@ void g() {
 #endif
 } // namespace cwg2877
 
-namespace cwg2881 { // cwg2881: 19 tentatively ready 2024-04-19
+namespace cwg2881 { // cwg2881: 19 ready 2024-04-19

Endilll wrote:

Since this was added, wording has changed slightly, and a new ill-formed 
example was added. See 
https://github.com/cplusplus/CWG/blame/gh-pages/issues/2881.html
CC @Sirraide

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


[clang] [NFC] [Clang] Some core issues have changed status from tentatively ready -> ready / review (PR #97200)

2024-06-30 Thread Vlad Serebrennikov via cfe-commits

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


[clang] [NFC] [Clang] Some core issues have changed status from tentatively ready -> ready / review (PR #97200)

2024-06-30 Thread Vlad Serebrennikov via cfe-commits

https://github.com/Endilll requested changes to this pull request.

Thank you for taking care of this!
But I'd like to emphasize that updating statuses of existing DR tests is not 
just a menial task, otherwise I wouldn't even bother making the script this 
strict about statuses in the first place.

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


[clang] [NFC] [Clang] Some core issues have changed status from tentatively ready -> ready / review (PR #97200)

2024-06-30 Thread Vlad Serebrennikov via cfe-commits


@@ -134,7 +134,7 @@ struct A {
 
 } // namespace cwg2858
 
-namespace cwg2877 { // cwg2877: 19 tentatively ready 2024-05-31
+namespace cwg2877 { // cwg2877: 19 ready 2024-05-31

Endilll wrote:

We should fix the comments as it was done in 
https://github.com/cplusplus/CWG/commit/b7022853d731983a4b15d0a3a5b4ca49dc1ff366

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


[clang] [llvm] [polly] Revert "[IR] Don't include Module.h in Analysis.h (NFC) (#97023)" (PR #97129)

2024-06-30 Thread Yi Kong via cfe-commits

kongy wrote:

> This is probably caused by some downstream patches in google3? 
> https://github.com/llvm/llvm-project/blob/main/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
>  does not contain any mentions of `M->getFunction` or `M->getContext`. You 
> need to add the missing include to your downstream patches.

Yes, The problem is from our Android downstream patch, 
Support-for-WASM-as-native-IR.patch.

https://android.googlesource.com/toolchain/llvm_android/+/refs/heads/main/patches/Support-for-WASM-as-native-IR.patch#121

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


[clang] [Clang] [C23] Implement N2653: u8 strings are char8_t[] (PR #97208)

2024-06-30 Thread Mital Ashok via cfe-commits

https://github.com/MitalAshok created 
https://github.com/llvm/llvm-project/pull/97208

https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2653.htm

Closes #97202


>From ef0072d1fc9b14f7ee657fa95f44a686b78b525a Mon Sep 17 00:00:00 2001
From: Mital Ashok 
Date: Sun, 30 Jun 2024 12:07:54 +0100
Subject: [PATCH] [Clang] [C23] Implement N2653: u8 strings are char8_t[]

---
 clang/docs/ReleaseNotes.rst   |  6 
 .../clang/Basic/DiagnosticSemaKinds.td|  5 +++-
 clang/lib/Frontend/InitPreprocessor.cpp   |  6 ++--
 clang/lib/Headers/stdatomic.h |  5 
 clang/lib/Sema/SemaExpr.cpp   | 23 ++-
 clang/test/C/C2x/n2653.c  | 29 +++
 clang/www/c_status.html   |  2 +-
 7 files changed, 65 insertions(+), 11 deletions(-)
 create mode 100644 clang/test/C/C2x/n2653.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c720e47dbe35b..e51be81d8b11a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -337,6 +337,12 @@ C23 Feature Support
 - Properly promote bit-fields of bit-precise integer types to the field's type
   rather than to ``int``. #GH87641
 
+- Compiler support for `N2653 char8_t: A type for UTF-8 characters and strings`
+  `_: ``u8`` string
+  literals are now of type ``char8_t[N]`` in C23 and expose
+  ``__CLANG_ATOMIC_CHAR8_T_LOCK_FREE``/``__GCC_ATOMIC_CHAR8_T_LOCK_FREE`` to
+  implement the corresponding macro in .
+
 Non-comprehensive list of changes in this release
 -
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 5dc36c594bcb7..6a00b92df1c36 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -7252,7 +7252,10 @@ def err_array_init_utf8_string_into_char : Error<
 def warn_cxx20_compat_utf8_string : Warning<
   "type of UTF-8 string literal will change from array of const char to "
   "array of const char8_t in C++20">, InGroup, DefaultIgnore;
-def note_cxx20_compat_utf8_string_remove_u8 : Note<
+def warn_c23_compat_utf8_string : Warning<
+  "type of UTF-8 string literal will change from array of char to "
+  "array of char8_t in C23">, InGroup, DefaultIgnore;
+def note_cxx20_c23_compat_utf8_string_remove_u8 : Note<
   "remove 'u8' prefix to avoid a change of behavior; "
   "Clang encodes unprefixed narrow string literals as UTF-8">;
 def err_array_init_different_type : Error<
diff --git a/clang/lib/Frontend/InitPreprocessor.cpp 
b/clang/lib/Frontend/InitPreprocessor.cpp
index 55ec460064830..6270c37342bcf 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -1342,8 +1342,10 @@ static void InitializePredefinedMacros(const TargetInfo 
&TI,
   getLockFreeValue(TI.get##Type##Width(), TI));
 DEFINE_LOCK_FREE_MACRO(BOOL, Bool);
 DEFINE_LOCK_FREE_MACRO(CHAR, Char);
-if (LangOpts.Char8)
-  DEFINE_LOCK_FREE_MACRO(CHAR8_T, Char); // Treat char8_t like char.
+// char8_t has the same representation / width as unsigned
+// char in C++ and is a typedef for unsigned char in C23
+if (LangOpts.Char8 || LangOpts.C23)
+  DEFINE_LOCK_FREE_MACRO(CHAR8_T, Char);
 DEFINE_LOCK_FREE_MACRO(CHAR16_T, Char16);
 DEFINE_LOCK_FREE_MACRO(CHAR32_T, Char32);
 DEFINE_LOCK_FREE_MACRO(WCHAR_T, WChar);
diff --git a/clang/lib/Headers/stdatomic.h b/clang/lib/Headers/stdatomic.h
index 9c103d98af8c5..c33cd8083525c 100644
--- a/clang/lib/Headers/stdatomic.h
+++ b/clang/lib/Headers/stdatomic.h
@@ -35,6 +35,10 @@ extern "C" {
 
 #define ATOMIC_BOOL_LOCK_FREE   __CLANG_ATOMIC_BOOL_LOCK_FREE
 #define ATOMIC_CHAR_LOCK_FREE   __CLANG_ATOMIC_CHAR_LOCK_FREE
+#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L) ||  
\
+defined(__cplusplus)
+#define ATOMIC_CHAR8_T_LOCK_FREE__CLANG_ATOMIC_CHAR8_T_LOCK_FREE
+#endif
 #define ATOMIC_CHAR16_T_LOCK_FREE   __CLANG_ATOMIC_CHAR16_T_LOCK_FREE
 #define ATOMIC_CHAR32_T_LOCK_FREE   __CLANG_ATOMIC_CHAR32_T_LOCK_FREE
 #define ATOMIC_WCHAR_T_LOCK_FREE__CLANG_ATOMIC_WCHAR_T_LOCK_FREE
@@ -104,6 +108,7 @@ typedef _Atomic(long)   atomic_long;
 typedef _Atomic(unsigned long)  atomic_ulong;
 typedef _Atomic(long long)  atomic_llong;
 typedef _Atomic(unsigned long long) atomic_ullong;
+typedef _Atomic(unsigned char)  atomic_char8_t;
 typedef _Atomic(uint_least16_t) atomic_char16_t;
 typedef _Atomic(uint_least32_t) atomic_char32_t;
 typedef _Atomic(wchar_t)atomic_wchar_t;
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index db44cfe1288b6..a1b060f7f1510 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -2082,6 +2082,8 @@ Sema::ActOnStringLiteral(ArrayRef S

[clang] [Clang] [C23] Implement N2653: u8 strings are char8_t[] (PR #97208)

2024-06-30 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-x86

Author: Mital Ashok (MitalAshok)


Changes

https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2653.htm

Closes #97202


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


7 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+6) 
- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+4-1) 
- (modified) clang/lib/Frontend/InitPreprocessor.cpp (+4-2) 
- (modified) clang/lib/Headers/stdatomic.h (+5) 
- (modified) clang/lib/Sema/SemaExpr.cpp (+16-7) 
- (added) clang/test/C/C2x/n2653.c (+29) 
- (modified) clang/www/c_status.html (+1-1) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c720e47dbe35b..e51be81d8b11a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -337,6 +337,12 @@ C23 Feature Support
 - Properly promote bit-fields of bit-precise integer types to the field's type
   rather than to ``int``. #GH87641
 
+- Compiler support for `N2653 char8_t: A type for UTF-8 characters and strings`
+  `_: ``u8`` string
+  literals are now of type ``char8_t[N]`` in C23 and expose
+  ``__CLANG_ATOMIC_CHAR8_T_LOCK_FREE``/``__GCC_ATOMIC_CHAR8_T_LOCK_FREE`` to
+  implement the corresponding macro in .
+
 Non-comprehensive list of changes in this release
 -
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 5dc36c594bcb7..6a00b92df1c36 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -7252,7 +7252,10 @@ def err_array_init_utf8_string_into_char : Error<
 def warn_cxx20_compat_utf8_string : Warning<
   "type of UTF-8 string literal will change from array of const char to "
   "array of const char8_t in C++20">, InGroup, DefaultIgnore;
-def note_cxx20_compat_utf8_string_remove_u8 : Note<
+def warn_c23_compat_utf8_string : Warning<
+  "type of UTF-8 string literal will change from array of char to "
+  "array of char8_t in C23">, InGroup, DefaultIgnore;
+def note_cxx20_c23_compat_utf8_string_remove_u8 : Note<
   "remove 'u8' prefix to avoid a change of behavior; "
   "Clang encodes unprefixed narrow string literals as UTF-8">;
 def err_array_init_different_type : Error<
diff --git a/clang/lib/Frontend/InitPreprocessor.cpp 
b/clang/lib/Frontend/InitPreprocessor.cpp
index 55ec460064830..6270c37342bcf 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -1342,8 +1342,10 @@ static void InitializePredefinedMacros(const TargetInfo 
&TI,
   getLockFreeValue(TI.get##Type##Width(), TI));
 DEFINE_LOCK_FREE_MACRO(BOOL, Bool);
 DEFINE_LOCK_FREE_MACRO(CHAR, Char);
-if (LangOpts.Char8)
-  DEFINE_LOCK_FREE_MACRO(CHAR8_T, Char); // Treat char8_t like char.
+// char8_t has the same representation / width as unsigned
+// char in C++ and is a typedef for unsigned char in C23
+if (LangOpts.Char8 || LangOpts.C23)
+  DEFINE_LOCK_FREE_MACRO(CHAR8_T, Char);
 DEFINE_LOCK_FREE_MACRO(CHAR16_T, Char16);
 DEFINE_LOCK_FREE_MACRO(CHAR32_T, Char32);
 DEFINE_LOCK_FREE_MACRO(WCHAR_T, WChar);
diff --git a/clang/lib/Headers/stdatomic.h b/clang/lib/Headers/stdatomic.h
index 9c103d98af8c5..c33cd8083525c 100644
--- a/clang/lib/Headers/stdatomic.h
+++ b/clang/lib/Headers/stdatomic.h
@@ -35,6 +35,10 @@ extern "C" {
 
 #define ATOMIC_BOOL_LOCK_FREE   __CLANG_ATOMIC_BOOL_LOCK_FREE
 #define ATOMIC_CHAR_LOCK_FREE   __CLANG_ATOMIC_CHAR_LOCK_FREE
+#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L) ||  
\
+defined(__cplusplus)
+#define ATOMIC_CHAR8_T_LOCK_FREE__CLANG_ATOMIC_CHAR8_T_LOCK_FREE
+#endif
 #define ATOMIC_CHAR16_T_LOCK_FREE   __CLANG_ATOMIC_CHAR16_T_LOCK_FREE
 #define ATOMIC_CHAR32_T_LOCK_FREE   __CLANG_ATOMIC_CHAR32_T_LOCK_FREE
 #define ATOMIC_WCHAR_T_LOCK_FREE__CLANG_ATOMIC_WCHAR_T_LOCK_FREE
@@ -104,6 +108,7 @@ typedef _Atomic(long)   atomic_long;
 typedef _Atomic(unsigned long)  atomic_ulong;
 typedef _Atomic(long long)  atomic_llong;
 typedef _Atomic(unsigned long long) atomic_ullong;
+typedef _Atomic(unsigned char)  atomic_char8_t;
 typedef _Atomic(uint_least16_t) atomic_char16_t;
 typedef _Atomic(uint_least32_t) atomic_char32_t;
 typedef _Atomic(wchar_t)atomic_wchar_t;
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index db44cfe1288b6..a1b060f7f1510 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -2082,6 +2082,8 @@ Sema::ActOnStringLiteral(ArrayRef StringToks, 
Scope *UDLScope) {
   } else if (Literal.isUTF8()) {
 if (getLangOpts().Char8)
   CharTy = Context.Char8Ty;
+else if (getLangOpts().C23)
+  CharTy = Context.UnsignedCharTy;
 Kind = StringLiteralKind::UTF8;
   } else i

[clang] [Clang] [C23] Implement N2653: u8 strings are char8_t[] (PR #97208)

2024-06-30 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Mital Ashok (MitalAshok)


Changes

https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2653.htm

Closes #97202


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


7 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+6) 
- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+4-1) 
- (modified) clang/lib/Frontend/InitPreprocessor.cpp (+4-2) 
- (modified) clang/lib/Headers/stdatomic.h (+5) 
- (modified) clang/lib/Sema/SemaExpr.cpp (+16-7) 
- (added) clang/test/C/C2x/n2653.c (+29) 
- (modified) clang/www/c_status.html (+1-1) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c720e47dbe35b..e51be81d8b11a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -337,6 +337,12 @@ C23 Feature Support
 - Properly promote bit-fields of bit-precise integer types to the field's type
   rather than to ``int``. #GH87641
 
+- Compiler support for `N2653 char8_t: A type for UTF-8 characters and strings`
+  `_: ``u8`` string
+  literals are now of type ``char8_t[N]`` in C23 and expose
+  ``__CLANG_ATOMIC_CHAR8_T_LOCK_FREE``/``__GCC_ATOMIC_CHAR8_T_LOCK_FREE`` to
+  implement the corresponding macro in .
+
 Non-comprehensive list of changes in this release
 -
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 5dc36c594bcb7..6a00b92df1c36 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -7252,7 +7252,10 @@ def err_array_init_utf8_string_into_char : Error<
 def warn_cxx20_compat_utf8_string : Warning<
   "type of UTF-8 string literal will change from array of const char to "
   "array of const char8_t in C++20">, InGroup, DefaultIgnore;
-def note_cxx20_compat_utf8_string_remove_u8 : Note<
+def warn_c23_compat_utf8_string : Warning<
+  "type of UTF-8 string literal will change from array of char to "
+  "array of char8_t in C23">, InGroup, DefaultIgnore;
+def note_cxx20_c23_compat_utf8_string_remove_u8 : Note<
   "remove 'u8' prefix to avoid a change of behavior; "
   "Clang encodes unprefixed narrow string literals as UTF-8">;
 def err_array_init_different_type : Error<
diff --git a/clang/lib/Frontend/InitPreprocessor.cpp 
b/clang/lib/Frontend/InitPreprocessor.cpp
index 55ec460064830..6270c37342bcf 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -1342,8 +1342,10 @@ static void InitializePredefinedMacros(const TargetInfo 
&TI,
   getLockFreeValue(TI.get##Type##Width(), TI));
 DEFINE_LOCK_FREE_MACRO(BOOL, Bool);
 DEFINE_LOCK_FREE_MACRO(CHAR, Char);
-if (LangOpts.Char8)
-  DEFINE_LOCK_FREE_MACRO(CHAR8_T, Char); // Treat char8_t like char.
+// char8_t has the same representation / width as unsigned
+// char in C++ and is a typedef for unsigned char in C23
+if (LangOpts.Char8 || LangOpts.C23)
+  DEFINE_LOCK_FREE_MACRO(CHAR8_T, Char);
 DEFINE_LOCK_FREE_MACRO(CHAR16_T, Char16);
 DEFINE_LOCK_FREE_MACRO(CHAR32_T, Char32);
 DEFINE_LOCK_FREE_MACRO(WCHAR_T, WChar);
diff --git a/clang/lib/Headers/stdatomic.h b/clang/lib/Headers/stdatomic.h
index 9c103d98af8c5..c33cd8083525c 100644
--- a/clang/lib/Headers/stdatomic.h
+++ b/clang/lib/Headers/stdatomic.h
@@ -35,6 +35,10 @@ extern "C" {
 
 #define ATOMIC_BOOL_LOCK_FREE   __CLANG_ATOMIC_BOOL_LOCK_FREE
 #define ATOMIC_CHAR_LOCK_FREE   __CLANG_ATOMIC_CHAR_LOCK_FREE
+#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L) ||  
\
+defined(__cplusplus)
+#define ATOMIC_CHAR8_T_LOCK_FREE__CLANG_ATOMIC_CHAR8_T_LOCK_FREE
+#endif
 #define ATOMIC_CHAR16_T_LOCK_FREE   __CLANG_ATOMIC_CHAR16_T_LOCK_FREE
 #define ATOMIC_CHAR32_T_LOCK_FREE   __CLANG_ATOMIC_CHAR32_T_LOCK_FREE
 #define ATOMIC_WCHAR_T_LOCK_FREE__CLANG_ATOMIC_WCHAR_T_LOCK_FREE
@@ -104,6 +108,7 @@ typedef _Atomic(long)   atomic_long;
 typedef _Atomic(unsigned long)  atomic_ulong;
 typedef _Atomic(long long)  atomic_llong;
 typedef _Atomic(unsigned long long) atomic_ullong;
+typedef _Atomic(unsigned char)  atomic_char8_t;
 typedef _Atomic(uint_least16_t) atomic_char16_t;
 typedef _Atomic(uint_least32_t) atomic_char32_t;
 typedef _Atomic(wchar_t)atomic_wchar_t;
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index db44cfe1288b6..a1b060f7f1510 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -2082,6 +2082,8 @@ Sema::ActOnStringLiteral(ArrayRef StringToks, 
Scope *UDLScope) {
   } else if (Literal.isUTF8()) {
 if (getLangOpts().Char8)
   CharTy = Context.Char8Ty;
+else if (getLangOpts().C23)
+  CharTy = Context.UnsignedCharTy;
 Kind = StringLiteralKind::UTF8;
   } else if (Lit

[clang] [Clang] [C23] Implement N2653: u8 strings are char8_t[] (PR #97208)

2024-06-30 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 7d33d4720f85fa2df7c1307bcc185017b6e4dd25 
ef0072d1fc9b14f7ee657fa95f44a686b78b525a -- clang/test/C/C2x/n2653.c 
clang/lib/Frontend/InitPreprocessor.cpp clang/lib/Headers/stdatomic.h 
clang/lib/Sema/SemaExpr.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Headers/stdatomic.h b/clang/lib/Headers/stdatomic.h
index c33cd80835..a5359358ff 100644
--- a/clang/lib/Headers/stdatomic.h
+++ b/clang/lib/Headers/stdatomic.h
@@ -37,7 +37,7 @@ extern "C" {
 #define ATOMIC_CHAR_LOCK_FREE   __CLANG_ATOMIC_CHAR_LOCK_FREE
 #if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L) ||  
\
 defined(__cplusplus)
-#define ATOMIC_CHAR8_T_LOCK_FREE__CLANG_ATOMIC_CHAR8_T_LOCK_FREE
+#define ATOMIC_CHAR8_T_LOCK_FREE __CLANG_ATOMIC_CHAR8_T_LOCK_FREE
 #endif
 #define ATOMIC_CHAR16_T_LOCK_FREE   __CLANG_ATOMIC_CHAR16_T_LOCK_FREE
 #define ATOMIC_CHAR32_T_LOCK_FREE   __CLANG_ATOMIC_CHAR32_T_LOCK_FREE
@@ -108,7 +108,7 @@ typedef _Atomic(long)   atomic_long;
 typedef _Atomic(unsigned long)  atomic_ulong;
 typedef _Atomic(long long)  atomic_llong;
 typedef _Atomic(unsigned long long) atomic_ullong;
-typedef _Atomic(unsigned char)  atomic_char8_t;
+typedef _Atomic(unsigned char) atomic_char8_t;
 typedef _Atomic(uint_least16_t) atomic_char16_t;
 typedef _Atomic(uint_least32_t) atomic_char32_t;
 typedef _Atomic(wchar_t)atomic_wchar_t;

``




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


[clang] [Clang] [C23] Implement N2653: u8 strings are char8_t[] (PR #97208)

2024-06-30 Thread Mital Ashok via cfe-commits

MitalAshok wrote:

CC @AaronBallman

Also the clang-format issues are intentional to fit the style of the 
surrounding lines

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


[clang] [Clang] Warn with -Wpre-c23-compat instead of -Wpre-c++17-compat for u8 character literals in C23 (PR #97210)

2024-06-30 Thread Mital Ashok via cfe-commits

https://github.com/MitalAshok created 
https://github.com/llvm/llvm-project/pull/97210

None

>From c6ee783243e1888074778e2cb6de05df41cc8333 Mon Sep 17 00:00:00 2001
From: Mital Ashok 
Date: Sun, 30 Jun 2024 12:55:04 +0100
Subject: [PATCH] [Clang] Warn with -Wpre-c23-compat instead of
 -Wpre-c++17-compat for u8 character literals in C23

---
 clang/docs/ReleaseNotes.rst | 2 ++
 clang/include/clang/Basic/DiagnosticLexKinds.td | 3 +++
 clang/lib/Lex/Lexer.cpp | 4 +++-
 clang/test/Sema/pre-c2x-compat.c| 1 +
 4 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c720e47dbe35b..d2939ef7a875c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -627,6 +627,8 @@ Improvements to Clang's diagnostics
   used rather than when they are needed for constant evaluation or when code 
is generated for them.
   The check is now stricter to prevent crashes for some unsupported 
declarations (Fixes #GH95495).
 
+- Clang now warns for u8 character literals used in C23 with 
``-Wpre-c23-compat`` instead of ``-Wpre-c++17-compat``.
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/include/clang/Basic/DiagnosticLexKinds.td 
b/clang/include/clang/Basic/DiagnosticLexKinds.td
index 12d7b8c0205ee..fc14bb6aa2165 100644
--- a/clang/include/clang/Basic/DiagnosticLexKinds.td
+++ b/clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -283,6 +283,9 @@ def warn_cxx98_compat_unicode_literal : Warning<
 def warn_cxx14_compat_u8_character_literal : Warning<
   "unicode literals are incompatible with C++ standards before C++17">,
   InGroup, DefaultIgnore;
+def warn_c17_compat_u8_character_literal : Warning<
+  "unicode literals are incompatible with C standards before C23">,
+  InGroup, DefaultIgnore;
 def warn_cxx11_compat_user_defined_literal : Warning<
   "identifier after literal will be treated as a user-defined literal suffix "
   "in C++11">, InGroup, DefaultIgnore;
diff --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp
index e59c7805b3862..c61d81e93d990 100644
--- a/clang/lib/Lex/Lexer.cpp
+++ b/clang/lib/Lex/Lexer.cpp
@@ -2428,7 +2428,9 @@ bool Lexer::LexCharConstant(Token &Result, const char 
*CurPtr,
   ? diag::warn_cxx98_compat_unicode_literal
   : diag::warn_c99_compat_unicode_literal);
 else if (Kind == tok::utf8_char_constant)
-  Diag(BufferPtr, diag::warn_cxx14_compat_u8_character_literal);
+  Diag(BufferPtr, LangOpts.CPlusPlus
+  ? diag::warn_cxx14_compat_u8_character_literal
+  : diag::warn_c17_compat_u8_character_literal);
   }
 
   char C = getAndAdvanceChar(CurPtr, Result);
diff --git a/clang/test/Sema/pre-c2x-compat.c b/clang/test/Sema/pre-c2x-compat.c
index fad472f1f72d5..15bb9b58349fa 100644
--- a/clang/test/Sema/pre-c2x-compat.c
+++ b/clang/test/Sema/pre-c2x-compat.c
@@ -1,3 +1,4 @@
 // RUN: %clang_cc1 %s -std=c2x -Wpre-c2x-compat -pedantic -fsyntax-only -verify
 
 int digit_seps = 123'456; // expected-warning {{digit separators are 
incompatible with C standards before C23}}
+unsigned char u8_char = u8'x'; // expected-warning {{unicode literals are 
incompatible with C standards before C23}}

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


[clang] [Clang] Warn with -Wpre-c23-compat instead of -Wpre-c++17-compat for u8 character literals in C23 (PR #97210)

2024-06-30 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Mital Ashok (MitalAshok)


Changes



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


4 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+2) 
- (modified) clang/include/clang/Basic/DiagnosticLexKinds.td (+3) 
- (modified) clang/lib/Lex/Lexer.cpp (+3-1) 
- (modified) clang/test/Sema/pre-c2x-compat.c (+1) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c720e47dbe35b..d2939ef7a875c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -627,6 +627,8 @@ Improvements to Clang's diagnostics
   used rather than when they are needed for constant evaluation or when code 
is generated for them.
   The check is now stricter to prevent crashes for some unsupported 
declarations (Fixes #GH95495).
 
+- Clang now warns for u8 character literals used in C23 with 
``-Wpre-c23-compat`` instead of ``-Wpre-c++17-compat``.
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/include/clang/Basic/DiagnosticLexKinds.td 
b/clang/include/clang/Basic/DiagnosticLexKinds.td
index 12d7b8c0205ee..fc14bb6aa2165 100644
--- a/clang/include/clang/Basic/DiagnosticLexKinds.td
+++ b/clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -283,6 +283,9 @@ def warn_cxx98_compat_unicode_literal : Warning<
 def warn_cxx14_compat_u8_character_literal : Warning<
   "unicode literals are incompatible with C++ standards before C++17">,
   InGroup, DefaultIgnore;
+def warn_c17_compat_u8_character_literal : Warning<
+  "unicode literals are incompatible with C standards before C23">,
+  InGroup, DefaultIgnore;
 def warn_cxx11_compat_user_defined_literal : Warning<
   "identifier after literal will be treated as a user-defined literal suffix "
   "in C++11">, InGroup, DefaultIgnore;
diff --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp
index e59c7805b3862..c61d81e93d990 100644
--- a/clang/lib/Lex/Lexer.cpp
+++ b/clang/lib/Lex/Lexer.cpp
@@ -2428,7 +2428,9 @@ bool Lexer::LexCharConstant(Token &Result, const char 
*CurPtr,
   ? diag::warn_cxx98_compat_unicode_literal
   : diag::warn_c99_compat_unicode_literal);
 else if (Kind == tok::utf8_char_constant)
-  Diag(BufferPtr, diag::warn_cxx14_compat_u8_character_literal);
+  Diag(BufferPtr, LangOpts.CPlusPlus
+  ? diag::warn_cxx14_compat_u8_character_literal
+  : diag::warn_c17_compat_u8_character_literal);
   }
 
   char C = getAndAdvanceChar(CurPtr, Result);
diff --git a/clang/test/Sema/pre-c2x-compat.c b/clang/test/Sema/pre-c2x-compat.c
index fad472f1f72d5..15bb9b58349fa 100644
--- a/clang/test/Sema/pre-c2x-compat.c
+++ b/clang/test/Sema/pre-c2x-compat.c
@@ -1,3 +1,4 @@
 // RUN: %clang_cc1 %s -std=c2x -Wpre-c2x-compat -pedantic -fsyntax-only -verify
 
 int digit_seps = 123'456; // expected-warning {{digit separators are 
incompatible with C standards before C23}}
+unsigned char u8_char = u8'x'; // expected-warning {{unicode literals are 
incompatible with C standards before C23}}

``




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


[clang] [NFC] [Clang] Some core issues have changed status from tentatively ready -> ready / review (PR #97200)

2024-06-30 Thread Mital Ashok via cfe-commits

https://github.com/MitalAshok updated 
https://github.com/llvm/llvm-project/pull/97200

>From 0dea95701ca4dfca9b7d0bd889003fc35aa3017e Mon Sep 17 00:00:00 2001
From: Mital Ashok 
Date: Sun, 30 Jun 2024 10:39:15 +0100
Subject: [PATCH 1/8] [NFC] [Clang] Some core issues have changed status from
 tentatively ready -> ready / review

---
 clang/test/CXX/drs/cwg25xx.cpp |   2 +-
 clang/test/CXX/drs/cwg28xx.cpp |  16 ++--
 clang/www/cxx_dr_status.html   | 130 +++--
 clang/www/make_cxx_dr_status   |   6 +-
 4 files changed, 104 insertions(+), 50 deletions(-)

diff --git a/clang/test/CXX/drs/cwg25xx.cpp b/clang/test/CXX/drs/cwg25xx.cpp
index 0934f0cc19c6a..5f8a058f8157a 100644
--- a/clang/test/CXX/drs/cwg25xx.cpp
+++ b/clang/test/CXX/drs/cwg25xx.cpp
@@ -139,7 +139,7 @@ struct D3 : B {
 #endif
 
 #if __cplusplus >= 202302L
-namespace cwg2561 { // cwg2561: no tentatively ready 2024-03-18
+namespace cwg2561 { // cwg2561: no ready 2024-03-18
 struct C {
 constexpr C(auto) { }
 };
diff --git a/clang/test/CXX/drs/cwg28xx.cpp b/clang/test/CXX/drs/cwg28xx.cpp
index c77bd433d8e21..524e67b52de51 100644
--- a/clang/test/CXX/drs/cwg28xx.cpp
+++ b/clang/test/CXX/drs/cwg28xx.cpp
@@ -30,7 +30,7 @@ using U2 = decltype(&main);
 #endif
 } // namespace cwg2811
 
-namespace cwg2819 { // cwg2819: 19 tentatively ready 2023-12-01
+namespace cwg2819 { // cwg2819: 19 ready 2023-12-01
 #if __cpp_constexpr >= 202306L
   constexpr void* p = nullptr;
   constexpr int* q = static_cast(p);
@@ -111,7 +111,7 @@ struct D : N::B {
 #endif
 } // namespace cwg2857
 
-namespace cwg2858 { // cwg2858: 19 tentatively ready 2024-04-05
+namespace cwg2858 { // cwg2858: 19 ready 2024-04-05
 
 #if __cplusplus > 202302L
 
@@ -134,7 +134,7 @@ struct A {
 
 } // namespace cwg2858
 
-namespace cwg2877 { // cwg2877: 19 tentatively ready 2024-05-31
+namespace cwg2877 { // cwg2877: 19 ready 2024-05-31
 #if __cplusplus >= 202002L
 enum E { x };
 void f() {
@@ -150,7 +150,7 @@ void g() {
 #endif
 } // namespace cwg2877
 
-namespace cwg2881 { // cwg2881: 19 tentatively ready 2024-04-19
+namespace cwg2881 { // cwg2881: 19 ready 2024-04-19
 
 #if __cplusplus >= 202302L
 
@@ -220,7 +220,7 @@ void f() {
 
 } // namespace cwg2881
 
-namespace cwg2882 { // cwg2882: 2.7 tentatively ready 2024-05-31
+namespace cwg2882 { // cwg2882: 2.7 ready 2024-05-31
 struct C {
   operator void() = delete;
   // expected-warning@-1 {{conversion function converting 'cwg2882::C' to 
'void' will never be used}}
@@ -232,7 +232,7 @@ void f(C c) {
 }
 } // namespace cwg2882
 
-namespace cwg2883 { // cwg2883: no tentatively ready 2024-05-31
+namespace cwg2883 { // cwg2883: no ready 2024-05-31
 #if __cplusplus >= 201103L
 void f() {
   int x;
@@ -257,7 +257,7 @@ void g() {
 #endif
 } // namespace cwg2883
 
-namespace cwg2885 { // cwg2885: 16 tentatively ready 2024-05-31
+namespace cwg2885 { // cwg2885: 16 review 2024-05-31
 #if __cplusplus >= 202002L
 template 
 struct A {
@@ -271,7 +271,7 @@ static_assert(!__is_trivially_constructible(B));
 #endif
 } // namespace cwg2885
 
-namespace cwg2886 { // cwg2886: 9 tentatively ready 2024-05-31
+namespace cwg2886 { // cwg2886: 9 ready 2024-05-31
 #if __cplusplus >= 201103L
 struct C {
   C() = default;
diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index 937f67981e296..64b361976a5a5 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -1442,7 +1442,7 @@ C++ defect report implementation 
status
   
   
 https://cplusplus.github.io/CWG/issues/233.html";>233
-tentatively ready
+ready
 References vs pointers in UDC overload resolution
 Not resolved
   
@@ -7329,11 +7329,11 @@ C++ defect report implementation 
status
 Overloading member function templates based on dependent return 
type
 Unknown
   
-  
+  
 https://cplusplus.github.io/CWG/issues/1253.html";>1253
-open
+C++17
 Generic non-template members
-Not resolved
+Unknown
   
   
 https://cplusplus.github.io/CWG/issues/1254.html";>1254
@@ -12677,7 +12677,7 @@ C++ defect report implementation 
status
   
   
 https://cplusplus.github.io/CWG/issues/2144.html";>2144
-tentatively ready
+ready
 Function/variable declaration ambiguity
 Not resolved
   
@@ -15179,7 +15179,7 @@ C++ defect report implementation 
status
   
   
 https://cplusplus.github.io/CWG/issues/2561.html";>2561
-tentatively ready
+ready
 Conversion to function pointer for lambda with explicit object 
parameter
 Not Resolved*
   
@@ -15341,7 +15341,7 @@ C++ defect report implementation 
status
   
   
 https://cplusplus.github.io/CWG/issues/2588.html";>2588
-tentatively ready
+ready
 friend declarations and module linkage
 Not resolved
   
@@ -15541,7 +15541,7 @@ C++ defect report implementation 
status
 https://cplusplus.github.io/CWG/issues/2621.html";>2621
 C++23
 Kind of lookup for using enum declarations
-Superseded by 2877

[clang] [NFC] [Clang] Some core issues have changed status from tentatively ready -> ready / review (PR #97200)

2024-06-30 Thread Mital Ashok via cfe-commits


@@ -111,7 +111,7 @@ struct D : N::B {
 #endif
 } // namespace cwg2857
 
-namespace cwg2858 { // cwg2858: 19 tentatively ready 2024-04-05
+namespace cwg2858 { // cwg2858: 19 ready 2024-04-05

MitalAshok wrote:

The date of the proposed resolution did not change for this one: 
https://cplusplus.github.io/CWG/issues/2858.html

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


[clang] [NFC] [Clang] Some core issues have changed status from tentatively ready -> ready / review (PR #97200)

2024-06-30 Thread Mital Ashok via cfe-commits

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


[clang-tools-extra] Enforce SL.con.3: Add check to replace operator[] with at() [Cont.] (PR #95220)

2024-06-30 Thread Paul Heidekrüger via cfe-commits

https://github.com/PBHDK updated https://github.com/llvm/llvm-project/pull/95220

From 37292995de0c5aa87408586749795a97468d4725 Mon Sep 17 00:00:00 2001
From: Sebastian Wolf 
Date: Wed, 17 Apr 2024 16:16:35 +0200
Subject: [PATCH 01/23] Enforce SL.con.3: Add check to replace operator[] with
 at() on std containers

---
 .../AvoidBoundsErrorsCheck.cpp| 81 +++
 .../AvoidBoundsErrorsCheck.h  | 32 
 .../cppcoreguidelines/CMakeLists.txt  |  1 +
 .../CppCoreGuidelinesTidyModule.cpp   |  3 +
 clang-tools-extra/docs/ReleaseNotes.rst   |  5 ++
 .../cppcoreguidelines/avoid-bounds-errors.rst | 20 +
 .../docs/clang-tidy/checks/list.rst   |  1 +
 .../cppcoreguidelines/avoid-bounds-errors.cpp | 66 +++
 8 files changed, 209 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidBoundsErrorsCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidBoundsErrorsCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-bounds-errors.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-bounds-errors.cpp

diff --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidBoundsErrorsCheck.cpp 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidBoundsErrorsCheck.cpp
new file mode 100644
index 0..524c21b5bdb81
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidBoundsErrorsCheck.cpp
@@ -0,0 +1,81 @@
+//===--- AvoidBoundsErrorsCheck.cpp - clang-tidy 
--===//
+//
+// 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
+//
+//===--===//
+
+#include "AvoidBoundsErrorsCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+
+#include 
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::cppcoreguidelines {
+
+bool isApplicable(const QualType &Type) {
+  const auto TypeStr = Type.getAsString();
+  bool Result = false;
+  // Only check for containers in the std namespace
+  if (TypeStr.find("std::vector") != std::string::npos) {
+Result = true;
+  }
+  if (TypeStr.find("std::array") != std::string::npos) {
+Result = true;
+  }
+  if (TypeStr.find("std::deque") != std::string::npos) {
+Result = true;
+  }
+  if (TypeStr.find("std::map") != std::string::npos) {
+Result = true;
+  }
+  if (TypeStr.find("std::unordered_map") != std::string::npos) {
+Result = true;
+  }
+  if (TypeStr.find("std::flat_map") != std::string::npos) {
+Result = true;
+  }
+  // TODO Add std::span with C++26
+  return Result;
+}
+
+void AvoidBoundsErrorsCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  callExpr(callee(cxxMethodDecl(hasName("operator[]")).bind("f")))
+  .bind("x"),
+  this);
+}
+
+void AvoidBoundsErrorsCheck::check(const MatchFinder::MatchResult &Result) {
+  const ASTContext &Context = *Result.Context;
+  const SourceManager &Source = Context.getSourceManager();
+  const auto *MatchedExpr = Result.Nodes.getNodeAs("x");
+  const auto *MatchedFunction = Result.Nodes.getNodeAs("f");
+  const auto Type = MatchedFunction->getThisType();
+  if (!isApplicable(Type)) {
+return;
+  }
+
+  // Get original code.
+  const SourceLocation b(MatchedExpr->getBeginLoc());
+  const SourceLocation e(MatchedExpr->getEndLoc());
+  const std::string OriginalCode =
+  Lexer::getSourceText(CharSourceRange::getTokenRange(b, e), Source,
+   getLangOpts())
+  .str();
+  const auto Range = SourceRange(b, e);
+
+  // Build replacement.
+  std::string NewCode = OriginalCode;
+  const auto BeginOpen = NewCode.find("[");
+  NewCode.replace(BeginOpen, 1, ".at(");
+  const auto BeginClose = NewCode.find("]");
+  NewCode.replace(BeginClose, 1, ")");
+
+  diag(MatchedExpr->getBeginLoc(), "Do not use operator[], use at() instead.")
+  << FixItHint::CreateReplacement(Range, NewCode);
+}
+
+} // namespace clang::tidy::cppcoreguidelines
diff --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidBoundsErrorsCheck.h 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidBoundsErrorsCheck.h
new file mode 100644
index 0..f915729cd7bbe
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidBoundsErrorsCheck.h
@@ -0,0 +1,32 @@
+//===--- AvoidBoundsErrorsCheck.h - clang-tidy --*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef 
LLV

[clang-tools-extra] Enforce SL.con.3: Add check to replace operator[] with at() [Cont.] (PR #95220)

2024-06-30 Thread Paul Heidekrüger via cfe-commits

https://github.com/PBHDK updated https://github.com/llvm/llvm-project/pull/95220

From 37292995de0c5aa87408586749795a97468d4725 Mon Sep 17 00:00:00 2001
From: Sebastian Wolf 
Date: Wed, 17 Apr 2024 16:16:35 +0200
Subject: [PATCH 01/24] Enforce SL.con.3: Add check to replace operator[] with
 at() on std containers

---
 .../AvoidBoundsErrorsCheck.cpp| 81 +++
 .../AvoidBoundsErrorsCheck.h  | 32 
 .../cppcoreguidelines/CMakeLists.txt  |  1 +
 .../CppCoreGuidelinesTidyModule.cpp   |  3 +
 clang-tools-extra/docs/ReleaseNotes.rst   |  5 ++
 .../cppcoreguidelines/avoid-bounds-errors.rst | 20 +
 .../docs/clang-tidy/checks/list.rst   |  1 +
 .../cppcoreguidelines/avoid-bounds-errors.cpp | 66 +++
 8 files changed, 209 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidBoundsErrorsCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidBoundsErrorsCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-bounds-errors.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-bounds-errors.cpp

diff --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidBoundsErrorsCheck.cpp 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidBoundsErrorsCheck.cpp
new file mode 100644
index 0..524c21b5bdb81
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidBoundsErrorsCheck.cpp
@@ -0,0 +1,81 @@
+//===--- AvoidBoundsErrorsCheck.cpp - clang-tidy 
--===//
+//
+// 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
+//
+//===--===//
+
+#include "AvoidBoundsErrorsCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+
+#include 
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::cppcoreguidelines {
+
+bool isApplicable(const QualType &Type) {
+  const auto TypeStr = Type.getAsString();
+  bool Result = false;
+  // Only check for containers in the std namespace
+  if (TypeStr.find("std::vector") != std::string::npos) {
+Result = true;
+  }
+  if (TypeStr.find("std::array") != std::string::npos) {
+Result = true;
+  }
+  if (TypeStr.find("std::deque") != std::string::npos) {
+Result = true;
+  }
+  if (TypeStr.find("std::map") != std::string::npos) {
+Result = true;
+  }
+  if (TypeStr.find("std::unordered_map") != std::string::npos) {
+Result = true;
+  }
+  if (TypeStr.find("std::flat_map") != std::string::npos) {
+Result = true;
+  }
+  // TODO Add std::span with C++26
+  return Result;
+}
+
+void AvoidBoundsErrorsCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  callExpr(callee(cxxMethodDecl(hasName("operator[]")).bind("f")))
+  .bind("x"),
+  this);
+}
+
+void AvoidBoundsErrorsCheck::check(const MatchFinder::MatchResult &Result) {
+  const ASTContext &Context = *Result.Context;
+  const SourceManager &Source = Context.getSourceManager();
+  const auto *MatchedExpr = Result.Nodes.getNodeAs("x");
+  const auto *MatchedFunction = Result.Nodes.getNodeAs("f");
+  const auto Type = MatchedFunction->getThisType();
+  if (!isApplicable(Type)) {
+return;
+  }
+
+  // Get original code.
+  const SourceLocation b(MatchedExpr->getBeginLoc());
+  const SourceLocation e(MatchedExpr->getEndLoc());
+  const std::string OriginalCode =
+  Lexer::getSourceText(CharSourceRange::getTokenRange(b, e), Source,
+   getLangOpts())
+  .str();
+  const auto Range = SourceRange(b, e);
+
+  // Build replacement.
+  std::string NewCode = OriginalCode;
+  const auto BeginOpen = NewCode.find("[");
+  NewCode.replace(BeginOpen, 1, ".at(");
+  const auto BeginClose = NewCode.find("]");
+  NewCode.replace(BeginClose, 1, ")");
+
+  diag(MatchedExpr->getBeginLoc(), "Do not use operator[], use at() instead.")
+  << FixItHint::CreateReplacement(Range, NewCode);
+}
+
+} // namespace clang::tidy::cppcoreguidelines
diff --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidBoundsErrorsCheck.h 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidBoundsErrorsCheck.h
new file mode 100644
index 0..f915729cd7bbe
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidBoundsErrorsCheck.h
@@ -0,0 +1,32 @@
+//===--- AvoidBoundsErrorsCheck.h - clang-tidy --*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef 
LLV

[clang] [llvm] [mlir] [MLIR] Add f8E4M3 IEEE 754 type (PR #97118)

2024-06-30 Thread Thorsten Schütt via cfe-commits

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


[clang] [Clang] Fix the order of addInstantiatedParameters in LambdaScopeForCallOperatorInstantiationRAII (PR #97215)

2024-06-30 Thread Yupei Liu via cfe-commits

https://github.com/LYP951018 created 
https://github.com/llvm/llvm-project/pull/97215

Currently, `addInstantiatedParameters` is called from the innermost lambda 
outward. However, when the function parameters of an inner lambda depend on the 
function parameters of an outer lambda, it can lead to a crash due to the 
inability to find a mapping for the instantiated decl.

This PR corrects this behavior by calling `addInstantiatedParameters` from the 
outside in.

repro code: https://godbolt.org/z/KbsxWesW6

```cpp
namespace dependent_param_concept {
template  void sink(Ts...) {}
void dependent_param() {
  auto L = [](auto... x) {
return [](decltype(x)... y) { // `y` depends on `x`
  return [](int z)
requires requires { sink(y..., z); }
  {};
};
  };
  L(0, 1)(1, 2)(1);
}
} // namespace dependent_param_concept
```

>From 832e5b29e44e6b8fd14eefeecd96000b187569b4 Mon Sep 17 00:00:00 2001
From: letrec 
Date: Sun, 30 Jun 2024 21:03:23 +0800
Subject: [PATCH 1/2] Fix the order of addInstantiatedParameters in
 LambdaScopeForCallOperatorInstantiationRAII.

---
 clang/lib/Sema/SemaLambda.cpp   | 39 +
 clang/test/SemaTemplate/concepts-lambda.cpp | 14 
 2 files changed, 38 insertions(+), 15 deletions(-)

diff --git a/clang/lib/Sema/SemaLambda.cpp b/clang/lib/Sema/SemaLambda.cpp
index e9476a0c93c5d..c5ed7b1dbfd56 100644
--- a/clang/lib/Sema/SemaLambda.cpp
+++ b/clang/lib/Sema/SemaLambda.cpp
@@ -2379,23 +2379,32 @@ Sema::LambdaScopeForCallOperatorInstantiationRAII::
 
   SemaRef.RebuildLambdaScopeInfo(cast(FD));
 
-  FunctionDecl *Pattern = getPatternFunctionDecl(FD);
-  if (Pattern) {
-SemaRef.addInstantiatedCapturesToScope(FD, Pattern, Scope, MLTAL);
+  FunctionDecl *FDPattern = getPatternFunctionDecl(FD);
+  if (!FDPattern)
+return;
 
-FunctionDecl *ParentFD = FD;
-while (ShouldAddDeclsFromParentScope) {
+  SemaRef.addInstantiatedCapturesToScope(FD, FDPattern, Scope, MLTAL);
 
-  ParentFD =
-  dyn_cast(getLambdaAwareParentOfDeclContext(ParentFD));
-  Pattern =
-  dyn_cast(getLambdaAwareParentOfDeclContext(Pattern));
+  if (!ShouldAddDeclsFromParentScope)
+return;
 
-  if (!FD || !Pattern)
-break;
+  llvm::SmallVector, 4>
+  ParentInstantiations;
+  std::pair Current = {FDPattern, FD};
+  while (true) {
+Current.first = dyn_cast(
+getLambdaAwareParentOfDeclContext(Current.first));
+Current.second = dyn_cast(
+getLambdaAwareParentOfDeclContext(Current.second));
 
-  SemaRef.addInstantiatedParametersToScope(ParentFD, Pattern, Scope, 
MLTAL);
-  SemaRef.addInstantiatedLocalVarsToScope(ParentFD, Pattern, Scope);
-}
+if (!Current.first || !Current.second)
+  break;
+
+ParentInstantiations.push_back(Current);
   }
-}
+
+  for (const auto &[Pattern, Inst] : llvm::reverse(ParentInstantiations)) {
+SemaRef.addInstantiatedParametersToScope(Inst, Pattern, Scope, MLTAL);
+SemaRef.addInstantiatedLocalVarsToScope(Inst, Pattern, Scope);
+  }
+}
\ No newline at end of file
diff --git a/clang/test/SemaTemplate/concepts-lambda.cpp 
b/clang/test/SemaTemplate/concepts-lambda.cpp
index 280be71284f97..252ef08549a48 100644
--- a/clang/test/SemaTemplate/concepts-lambda.cpp
+++ b/clang/test/SemaTemplate/concepts-lambda.cpp
@@ -237,3 +237,17 @@ concept D = []() { return true; }();
 D auto x = 0;
 
 } // namespace GH93821
+
+namespace dependent_param_concept {
+template  void sink(Ts...) {}
+void dependent_param() {
+  auto L = [](auto... x) {
+return [](decltype(x)... y) {
+  return [](int z)
+requires requires { sink(y..., z); }
+  {};
+};
+  };
+  L(0, 1)(1, 2)(1);
+}
+} // namespace dependent_param_concept

>From 015088dee066e710af0a9800c4f52b4cc1c062d7 Mon Sep 17 00:00:00 2001
From: letrec 
Date: Sun, 30 Jun 2024 21:07:43 +0800
Subject: [PATCH 2/2] add empty line

---
 clang/lib/Sema/SemaLambda.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaLambda.cpp b/clang/lib/Sema/SemaLambda.cpp
index c5ed7b1dbfd56..b6344f53861f4 100644
--- a/clang/lib/Sema/SemaLambda.cpp
+++ b/clang/lib/Sema/SemaLambda.cpp
@@ -2407,4 +2407,4 @@ Sema::LambdaScopeForCallOperatorInstantiationRAII::
 SemaRef.addInstantiatedParametersToScope(Inst, Pattern, Scope, MLTAL);
 SemaRef.addInstantiatedLocalVarsToScope(Inst, Pattern, Scope);
   }
-}
\ No newline at end of file
+}

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


[clang] [Clang] Fix the order of addInstantiatedParameters in LambdaScopeForCallOperatorInstantiationRAII (PR #97215)

2024-06-30 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Yupei Liu (LYP951018)


Changes

Currently, `addInstantiatedParameters` is called from the innermost lambda 
outward. However, when the function parameters of an inner lambda depend on the 
function parameters of an outer lambda, it can lead to a crash due to the 
inability to find a mapping for the instantiated decl.

This PR corrects this behavior by calling `addInstantiatedParameters` from the 
outside in.

repro code: https://godbolt.org/z/KbsxWesW6

```cpp
namespace dependent_param_concept {
template  void sink(Ts...) {}
void dependent_param() {
  auto L = [](auto... x) {
return [](decltype(x)... y) { // `y` depends on `x`
  return [](int z)
requires requires { sink(y..., z); }
  {};
};
  };
  L(0, 1)(1, 2)(1);
}
} // namespace dependent_param_concept
```

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


2 Files Affected:

- (modified) clang/lib/Sema/SemaLambda.cpp (+23-14) 
- (modified) clang/test/SemaTemplate/concepts-lambda.cpp (+14) 


``diff
diff --git a/clang/lib/Sema/SemaLambda.cpp b/clang/lib/Sema/SemaLambda.cpp
index e9476a0c93c5d..b6344f53861f4 100644
--- a/clang/lib/Sema/SemaLambda.cpp
+++ b/clang/lib/Sema/SemaLambda.cpp
@@ -2379,23 +2379,32 @@ Sema::LambdaScopeForCallOperatorInstantiationRAII::
 
   SemaRef.RebuildLambdaScopeInfo(cast(FD));
 
-  FunctionDecl *Pattern = getPatternFunctionDecl(FD);
-  if (Pattern) {
-SemaRef.addInstantiatedCapturesToScope(FD, Pattern, Scope, MLTAL);
+  FunctionDecl *FDPattern = getPatternFunctionDecl(FD);
+  if (!FDPattern)
+return;
 
-FunctionDecl *ParentFD = FD;
-while (ShouldAddDeclsFromParentScope) {
+  SemaRef.addInstantiatedCapturesToScope(FD, FDPattern, Scope, MLTAL);
 
-  ParentFD =
-  dyn_cast(getLambdaAwareParentOfDeclContext(ParentFD));
-  Pattern =
-  dyn_cast(getLambdaAwareParentOfDeclContext(Pattern));
+  if (!ShouldAddDeclsFromParentScope)
+return;
 
-  if (!FD || !Pattern)
-break;
+  llvm::SmallVector, 4>
+  ParentInstantiations;
+  std::pair Current = {FDPattern, FD};
+  while (true) {
+Current.first = dyn_cast(
+getLambdaAwareParentOfDeclContext(Current.first));
+Current.second = dyn_cast(
+getLambdaAwareParentOfDeclContext(Current.second));
 
-  SemaRef.addInstantiatedParametersToScope(ParentFD, Pattern, Scope, 
MLTAL);
-  SemaRef.addInstantiatedLocalVarsToScope(ParentFD, Pattern, Scope);
-}
+if (!Current.first || !Current.second)
+  break;
+
+ParentInstantiations.push_back(Current);
+  }
+
+  for (const auto &[Pattern, Inst] : llvm::reverse(ParentInstantiations)) {
+SemaRef.addInstantiatedParametersToScope(Inst, Pattern, Scope, MLTAL);
+SemaRef.addInstantiatedLocalVarsToScope(Inst, Pattern, Scope);
   }
 }
diff --git a/clang/test/SemaTemplate/concepts-lambda.cpp 
b/clang/test/SemaTemplate/concepts-lambda.cpp
index 280be71284f97..252ef08549a48 100644
--- a/clang/test/SemaTemplate/concepts-lambda.cpp
+++ b/clang/test/SemaTemplate/concepts-lambda.cpp
@@ -237,3 +237,17 @@ concept D = []() { return true; }();
 D auto x = 0;
 
 } // namespace GH93821
+
+namespace dependent_param_concept {
+template  void sink(Ts...) {}
+void dependent_param() {
+  auto L = [](auto... x) {
+return [](decltype(x)... y) {
+  return [](int z)
+requires requires { sink(y..., z); }
+  {};
+};
+  };
+  L(0, 1)(1, 2)(1);
+}
+} // namespace dependent_param_concept

``




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


[clang-tools-extra] Enforce SL.con.3: Add check to replace operator[] with at() [Cont.] (PR #95220)

2024-06-30 Thread Paul Heidekrüger via cfe-commits

https://github.com/PBHDK updated https://github.com/llvm/llvm-project/pull/95220

From 37292995de0c5aa87408586749795a97468d4725 Mon Sep 17 00:00:00 2001
From: Sebastian Wolf 
Date: Wed, 17 Apr 2024 16:16:35 +0200
Subject: [PATCH 01/25] Enforce SL.con.3: Add check to replace operator[] with
 at() on std containers

---
 .../AvoidBoundsErrorsCheck.cpp| 81 +++
 .../AvoidBoundsErrorsCheck.h  | 32 
 .../cppcoreguidelines/CMakeLists.txt  |  1 +
 .../CppCoreGuidelinesTidyModule.cpp   |  3 +
 clang-tools-extra/docs/ReleaseNotes.rst   |  5 ++
 .../cppcoreguidelines/avoid-bounds-errors.rst | 20 +
 .../docs/clang-tidy/checks/list.rst   |  1 +
 .../cppcoreguidelines/avoid-bounds-errors.cpp | 66 +++
 8 files changed, 209 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidBoundsErrorsCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidBoundsErrorsCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-bounds-errors.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-bounds-errors.cpp

diff --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidBoundsErrorsCheck.cpp 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidBoundsErrorsCheck.cpp
new file mode 100644
index 0..524c21b5bdb81
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidBoundsErrorsCheck.cpp
@@ -0,0 +1,81 @@
+//===--- AvoidBoundsErrorsCheck.cpp - clang-tidy 
--===//
+//
+// 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
+//
+//===--===//
+
+#include "AvoidBoundsErrorsCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+
+#include 
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::cppcoreguidelines {
+
+bool isApplicable(const QualType &Type) {
+  const auto TypeStr = Type.getAsString();
+  bool Result = false;
+  // Only check for containers in the std namespace
+  if (TypeStr.find("std::vector") != std::string::npos) {
+Result = true;
+  }
+  if (TypeStr.find("std::array") != std::string::npos) {
+Result = true;
+  }
+  if (TypeStr.find("std::deque") != std::string::npos) {
+Result = true;
+  }
+  if (TypeStr.find("std::map") != std::string::npos) {
+Result = true;
+  }
+  if (TypeStr.find("std::unordered_map") != std::string::npos) {
+Result = true;
+  }
+  if (TypeStr.find("std::flat_map") != std::string::npos) {
+Result = true;
+  }
+  // TODO Add std::span with C++26
+  return Result;
+}
+
+void AvoidBoundsErrorsCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  callExpr(callee(cxxMethodDecl(hasName("operator[]")).bind("f")))
+  .bind("x"),
+  this);
+}
+
+void AvoidBoundsErrorsCheck::check(const MatchFinder::MatchResult &Result) {
+  const ASTContext &Context = *Result.Context;
+  const SourceManager &Source = Context.getSourceManager();
+  const auto *MatchedExpr = Result.Nodes.getNodeAs("x");
+  const auto *MatchedFunction = Result.Nodes.getNodeAs("f");
+  const auto Type = MatchedFunction->getThisType();
+  if (!isApplicable(Type)) {
+return;
+  }
+
+  // Get original code.
+  const SourceLocation b(MatchedExpr->getBeginLoc());
+  const SourceLocation e(MatchedExpr->getEndLoc());
+  const std::string OriginalCode =
+  Lexer::getSourceText(CharSourceRange::getTokenRange(b, e), Source,
+   getLangOpts())
+  .str();
+  const auto Range = SourceRange(b, e);
+
+  // Build replacement.
+  std::string NewCode = OriginalCode;
+  const auto BeginOpen = NewCode.find("[");
+  NewCode.replace(BeginOpen, 1, ".at(");
+  const auto BeginClose = NewCode.find("]");
+  NewCode.replace(BeginClose, 1, ")");
+
+  diag(MatchedExpr->getBeginLoc(), "Do not use operator[], use at() instead.")
+  << FixItHint::CreateReplacement(Range, NewCode);
+}
+
+} // namespace clang::tidy::cppcoreguidelines
diff --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidBoundsErrorsCheck.h 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidBoundsErrorsCheck.h
new file mode 100644
index 0..f915729cd7bbe
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidBoundsErrorsCheck.h
@@ -0,0 +1,32 @@
+//===--- AvoidBoundsErrorsCheck.h - clang-tidy --*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef 
LLV

[clang] [Clang] Fix the order of addInstantiatedParameters in LambdaScopeForCallOperatorInstantiationRAII (PR #97215)

2024-06-30 Thread Yupei Liu via cfe-commits

https://github.com/LYP951018 updated 
https://github.com/llvm/llvm-project/pull/97215

>From a997ae70f86230200b1082c9bdc0bdf56e30b7c4 Mon Sep 17 00:00:00 2001
From: letrec 
Date: Sun, 30 Jun 2024 21:03:23 +0800
Subject: [PATCH] Fix the order of addInstantiatedParameters in
 LambdaScopeForCallOperatorInstantiationRAII.

---
 clang/lib/Sema/SemaLambda.cpp   | 37 +
 clang/test/SemaTemplate/concepts-lambda.cpp | 14 
 2 files changed, 37 insertions(+), 14 deletions(-)

diff --git a/clang/lib/Sema/SemaLambda.cpp b/clang/lib/Sema/SemaLambda.cpp
index ca9c7cb9faadf..b6344f53861f4 100644
--- a/clang/lib/Sema/SemaLambda.cpp
+++ b/clang/lib/Sema/SemaLambda.cpp
@@ -2379,23 +2379,32 @@ Sema::LambdaScopeForCallOperatorInstantiationRAII::
 
   SemaRef.RebuildLambdaScopeInfo(cast(FD));
 
-  FunctionDecl *Pattern = getPatternFunctionDecl(FD);
-  if (Pattern) {
-SemaRef.addInstantiatedCapturesToScope(FD, Pattern, Scope, MLTAL);
+  FunctionDecl *FDPattern = getPatternFunctionDecl(FD);
+  if (!FDPattern)
+return;
 
-FunctionDecl *ParentFD = FD;
-while (ShouldAddDeclsFromParentScope) {
+  SemaRef.addInstantiatedCapturesToScope(FD, FDPattern, Scope, MLTAL);
 
-  ParentFD =
-  dyn_cast(getLambdaAwareParentOfDeclContext(ParentFD));
-  Pattern =
-  dyn_cast(getLambdaAwareParentOfDeclContext(Pattern));
+  if (!ShouldAddDeclsFromParentScope)
+return;
 
-  if (!ParentFD || !Pattern)
-break;
+  llvm::SmallVector, 4>
+  ParentInstantiations;
+  std::pair Current = {FDPattern, FD};
+  while (true) {
+Current.first = dyn_cast(
+getLambdaAwareParentOfDeclContext(Current.first));
+Current.second = dyn_cast(
+getLambdaAwareParentOfDeclContext(Current.second));
 
-  SemaRef.addInstantiatedParametersToScope(ParentFD, Pattern, Scope, 
MLTAL);
-  SemaRef.addInstantiatedLocalVarsToScope(ParentFD, Pattern, Scope);
-}
+if (!Current.first || !Current.second)
+  break;
+
+ParentInstantiations.push_back(Current);
+  }
+
+  for (const auto &[Pattern, Inst] : llvm::reverse(ParentInstantiations)) {
+SemaRef.addInstantiatedParametersToScope(Inst, Pattern, Scope, MLTAL);
+SemaRef.addInstantiatedLocalVarsToScope(Inst, Pattern, Scope);
   }
 }
diff --git a/clang/test/SemaTemplate/concepts-lambda.cpp 
b/clang/test/SemaTemplate/concepts-lambda.cpp
index 280be71284f97..252ef08549a48 100644
--- a/clang/test/SemaTemplate/concepts-lambda.cpp
+++ b/clang/test/SemaTemplate/concepts-lambda.cpp
@@ -237,3 +237,17 @@ concept D = []() { return true; }();
 D auto x = 0;
 
 } // namespace GH93821
+
+namespace dependent_param_concept {
+template  void sink(Ts...) {}
+void dependent_param() {
+  auto L = [](auto... x) {
+return [](decltype(x)... y) {
+  return [](int z)
+requires requires { sink(y..., z); }
+  {};
+};
+  };
+  L(0, 1)(1, 2)(1);
+}
+} // namespace dependent_param_concept

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


[clang] [Clang] Fix the order of addInstantiatedParameters in LambdaScopeForCallOperatorInstantiationRAII (PR #97215)

2024-06-30 Thread Yupei Liu via cfe-commits

https://github.com/LYP951018 updated 
https://github.com/llvm/llvm-project/pull/97215

>From a997ae70f86230200b1082c9bdc0bdf56e30b7c4 Mon Sep 17 00:00:00 2001
From: letrec 
Date: Sun, 30 Jun 2024 21:03:23 +0800
Subject: [PATCH] Fix the order of addInstantiatedParameters in
 LambdaScopeForCallOperatorInstantiationRAII.

---
 clang/lib/Sema/SemaLambda.cpp   | 37 +
 clang/test/SemaTemplate/concepts-lambda.cpp | 14 
 2 files changed, 37 insertions(+), 14 deletions(-)

diff --git a/clang/lib/Sema/SemaLambda.cpp b/clang/lib/Sema/SemaLambda.cpp
index ca9c7cb9faadf..b6344f53861f4 100644
--- a/clang/lib/Sema/SemaLambda.cpp
+++ b/clang/lib/Sema/SemaLambda.cpp
@@ -2379,23 +2379,32 @@ Sema::LambdaScopeForCallOperatorInstantiationRAII::
 
   SemaRef.RebuildLambdaScopeInfo(cast(FD));
 
-  FunctionDecl *Pattern = getPatternFunctionDecl(FD);
-  if (Pattern) {
-SemaRef.addInstantiatedCapturesToScope(FD, Pattern, Scope, MLTAL);
+  FunctionDecl *FDPattern = getPatternFunctionDecl(FD);
+  if (!FDPattern)
+return;
 
-FunctionDecl *ParentFD = FD;
-while (ShouldAddDeclsFromParentScope) {
+  SemaRef.addInstantiatedCapturesToScope(FD, FDPattern, Scope, MLTAL);
 
-  ParentFD =
-  dyn_cast(getLambdaAwareParentOfDeclContext(ParentFD));
-  Pattern =
-  dyn_cast(getLambdaAwareParentOfDeclContext(Pattern));
+  if (!ShouldAddDeclsFromParentScope)
+return;
 
-  if (!ParentFD || !Pattern)
-break;
+  llvm::SmallVector, 4>
+  ParentInstantiations;
+  std::pair Current = {FDPattern, FD};
+  while (true) {
+Current.first = dyn_cast(
+getLambdaAwareParentOfDeclContext(Current.first));
+Current.second = dyn_cast(
+getLambdaAwareParentOfDeclContext(Current.second));
 
-  SemaRef.addInstantiatedParametersToScope(ParentFD, Pattern, Scope, 
MLTAL);
-  SemaRef.addInstantiatedLocalVarsToScope(ParentFD, Pattern, Scope);
-}
+if (!Current.first || !Current.second)
+  break;
+
+ParentInstantiations.push_back(Current);
+  }
+
+  for (const auto &[Pattern, Inst] : llvm::reverse(ParentInstantiations)) {
+SemaRef.addInstantiatedParametersToScope(Inst, Pattern, Scope, MLTAL);
+SemaRef.addInstantiatedLocalVarsToScope(Inst, Pattern, Scope);
   }
 }
diff --git a/clang/test/SemaTemplate/concepts-lambda.cpp 
b/clang/test/SemaTemplate/concepts-lambda.cpp
index 280be71284f97..252ef08549a48 100644
--- a/clang/test/SemaTemplate/concepts-lambda.cpp
+++ b/clang/test/SemaTemplate/concepts-lambda.cpp
@@ -237,3 +237,17 @@ concept D = []() { return true; }();
 D auto x = 0;
 
 } // namespace GH93821
+
+namespace dependent_param_concept {
+template  void sink(Ts...) {}
+void dependent_param() {
+  auto L = [](auto... x) {
+return [](decltype(x)... y) {
+  return [](int z)
+requires requires { sink(y..., z); }
+  {};
+};
+  };
+  L(0, 1)(1, 2)(1);
+}
+} // namespace dependent_param_concept

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


[clang] [Clang] Fix the order of addInstantiatedParameters in LambdaScopeForCallOperatorInstantiationRAII (PR #97215)

2024-06-30 Thread Yupei Liu via cfe-commits

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


[clang] [Clang] Fix the order of addInstantiatedParameters in LambdaScopeForCallOperatorInstantiationRAII (PR #97215)

2024-06-30 Thread Yupei Liu via cfe-commits

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


[clang] [Clang] Fix the order of addInstantiatedParameters in LambdaScopeForCallOperatorInstantiationRAII (PR #97215)

2024-06-30 Thread Yupei Liu via cfe-commits

LYP951018 wrote:

Sorry for disturbing... I'm trying to get the CI working. I can't figure out 
why buildkite/github-pull-requests failed... 

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


[clang] ac84ada - [clang] Avoid 'raw_string_ostream::str' (NFC)

2024-06-30 Thread Youngsuk Kim via cfe-commits

Author: Youngsuk Kim
Date: 2024-06-30T10:02:49-05:00
New Revision: ac84ada9a169a72ad136ef05c2c194f594f24a37

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

LOG: [clang] Avoid 'raw_string_ostream::str' (NFC)

Since `raw_string_ostream` doesn't own the string buffer, it is
desirable (in terms of memory safety) for users to directly reference
the string buffer rather than use `raw_string_ostream::str()`.

Work towards TODO comment to remove `raw_string_ostream::str()`.

Added: 


Modified: 
clang/lib/Tooling/Transformer/Stencil.cpp
clang/unittests/AST/MatchVerifier.h
clang/unittests/Interpreter/InterpreterTest.cpp
clang/unittests/Tooling/RecursiveASTVisitorTests/DeductionGuide.cpp
clang/unittests/Tooling/ReplacementsYamlTest.cpp

Removed: 




diff  --git a/clang/lib/Tooling/Transformer/Stencil.cpp 
b/clang/lib/Tooling/Transformer/Stencil.cpp
index d91c9e0a20cc1..bc4fa6e36057c 100644
--- a/clang/lib/Tooling/Transformer/Stencil.cpp
+++ b/clang/lib/Tooling/Transformer/Stencil.cpp
@@ -51,7 +51,7 @@ static Error printNode(StringRef Id, const 
MatchFinder::MatchResult &Match,
   if (auto Err = NodeOrErr.takeError())
 return Err;
   NodeOrErr->print(Os, PrintingPolicy(Match.Context->getLangOpts()));
-  *Result += Os.str();
+  *Result += Output;
   return Error::success();
 }
 
@@ -371,7 +371,7 @@ class SelectBoundStencil : public 
clang::transformer::StencilInterface {
   Stream << ", " << DefaultStencil->toString();
 }
 Stream << ")";
-return Stream.str();
+return Buffer;
   }
 
 private:

diff  --git a/clang/unittests/AST/MatchVerifier.h 
b/clang/unittests/AST/MatchVerifier.h
index da1e351da4a09..60bb4a8716ae8 100644
--- a/clang/unittests/AST/MatchVerifier.h
+++ b/clang/unittests/AST/MatchVerifier.h
@@ -209,7 +209,7 @@ class LocationVerifier : public MatchVerifier {
   << ">, found <";
   Loc.print(Msg, *Result.SourceManager);
   Msg << '>';
-  this->setFailure(Msg.str());
+  this->setFailure(MsgStr);
 }
   }
 
@@ -256,7 +256,7 @@ class RangeVerifier : public MatchVerifier {
   Msg << '-';
   End.print(Msg, *Result.SourceManager);
   Msg << '>';
-  this->setFailure(Msg.str());
+  this->setFailure(MsgStr);
 }
   }
 
@@ -282,12 +282,12 @@ class DumpVerifier : public MatchVerifier {
 llvm::raw_string_ostream Dump(DumpStr);
 Node.dump(Dump, *Result.Context);
 
-if (Dump.str().find(ExpectSubstring) == std::string::npos) {
+if (DumpStr.find(ExpectSubstring) == std::string::npos) {
   std::string MsgStr;
   llvm::raw_string_ostream Msg(MsgStr);
   Msg << "Expected dump substring <" << ExpectSubstring << ">, found <"
-  << Dump.str() << '>';
-  this->setFailure(Msg.str());
+  << DumpStr << '>';
+  this->setFailure(MsgStr);
 }
   }
 
@@ -309,12 +309,12 @@ class PrintVerifier : public MatchVerifier {
 llvm::raw_string_ostream Print(PrintStr);
 Node.print(Print, Result.Context->getPrintingPolicy());
 
-if (Print.str() != ExpectString) {
+if (PrintStr != ExpectString) {
   std::string MsgStr;
   llvm::raw_string_ostream Msg(MsgStr);
   Msg << "Expected pretty print <" << ExpectString << ">, found <"
-  << Print.str() << '>';
-  this->setFailure(Msg.str());
+  << PrintStr << '>';
+  this->setFailure(MsgStr);
 }
   }
 

diff  --git a/clang/unittests/Interpreter/InterpreterTest.cpp 
b/clang/unittests/Interpreter/InterpreterTest.cpp
index bbd854149d5f5..29c5ead60b81e 100644
--- a/clang/unittests/Interpreter/InterpreterTest.cpp
+++ b/clang/unittests/Interpreter/InterpreterTest.cpp
@@ -101,7 +101,7 @@ TEST_F(InterpreterTest, Errors) {
   auto Interp = createInterpreter(ExtraArgs, DiagPrinter.get());
   auto Err = Interp->Parse("intentional_error v1 = 42; ").takeError();
   using ::testing::HasSubstr;
-  EXPECT_THAT(DiagnosticsOS.str(),
+  EXPECT_THAT(DiagnosticOutput,
   HasSubstr("error: unknown type name 'intentional_error'"));
   EXPECT_EQ("Parsing failed.", llvm::toString(std::move(Err)));
 
@@ -186,7 +186,7 @@ static std::string MangleName(NamedDecl *ND) {
   std::string mangledName;
   llvm::raw_string_ostream RawStr(mangledName);
   MangleC->mangleName(ND, RawStr);
-  return RawStr.str();
+  return mangledName;
 }
 
 TEST_F(InterpreterTest, FindMangledNameSymbol) {

diff  --git 
a/clang/unittests/Tooling/RecursiveASTVisitorTests/DeductionGuide.cpp 
b/clang/unittests/Tooling/RecursiveASTVisitorTests/DeductionGuide.cpp
index 274f275ea66a9..cd4bf0eb7bd5a 100644
--- a/clang/unittests/Tooling/RecursiveASTVisitorTests/DeductionGuide.cpp
+++ b/clang/unittests/Tooling/RecursiveASTVisitorTests/DeductionGuide.cpp
@@ -22,7 +22,7 @@ class DeductionGuideVisitor
 std::string Storage;
 ll

[clang-tools-extra] [clang-doc] switched from using relative to absolute paths (PR #93281)

2024-06-30 Thread Paul Kirth via cfe-commits


@@ -0,0 +1,7 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t

ilovepi wrote:

nit: Can be one line w/ `&&`

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


[clang-tools-extra] [clang-doc] switched from using relative to absolute paths (PR #93281)

2024-06-30 Thread Paul Kirth via cfe-commits


@@ -0,0 +1,7 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "CHECK: var RootPath = \"%t\";" > %t/check.txt
+// RUN: cp "%s" "%t/test.cpp"

ilovepi wrote:

what is this doing? `CHECK` lines belong in the test file, generally. If you 
need to split them up somehow, there is the `split-file` utility 
(https://llvm.org/docs/TestingGuide.html#extra-files). But in this case, you 
don't need that at all, since these lines can be in this file

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


[clang-tools-extra] [clang-doc] switched from using relative to absolute paths (PR #93281)

2024-06-30 Thread Paul Kirth via cfe-commits


@@ -0,0 +1,7 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "CHECK: var RootPath = \"%t\";" > %t/check.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --doxygen --executor=standalone -p %t %t/test.cpp 
-output=%t/docs
+// RUN: FileCheck %t/check.txt -input-file=%t/docs/index_json.js
+// RUN: rm -rf %t

ilovepi wrote:

the `rm -rf` line should be first. It's very useful to be able to examine the 
test files you generate when they break. If you do it this way, its likely that 
they're deleted. Also, unless there's gong to be a need for multiple 
directories, I don't think you need anything but `%t`.

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


[clang-tools-extra] [clang-doc] switched from using relative to absolute paths (PR #93281)

2024-06-30 Thread Paul Kirth via cfe-commits


@@ -0,0 +1,8 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --doxygen --executor=standalone -p %t %t/test.cpp 
-output=../docs
+// RUN: FileCheck %s -input-file=%t/docs/index_json.js
+// RUN: rm -rf %t
+
+// CHECK: var RootPath = "{{.*}}../docs";

ilovepi wrote:

You don't need this file. All the checks can go in the other file. You can 
separate them w/ different identifiers w/ `--check-prefixes=FOO` in `FileCheck` 
commands. If you look at almost any test folder in LLVM you'll see examples. 
Also, 
https://llvm.org/docs/CommandGuide/FileCheck.html#cmdoption-FileCheck-check-prefix.

Also, don't copy files that aren't needed. `%s` is good enough for all the 
cases that I see.

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


[clang] [Clang] Fix the order of addInstantiatedParameters in LambdaScopeForCallOperatorInstantiationRAII (PR #97215)

2024-06-30 Thread Yupei Liu via cfe-commits

https://github.com/LYP951018 updated 
https://github.com/llvm/llvm-project/pull/97215

>From a997ae70f86230200b1082c9bdc0bdf56e30b7c4 Mon Sep 17 00:00:00 2001
From: letrec 
Date: Sun, 30 Jun 2024 21:03:23 +0800
Subject: [PATCH] Fix the order of addInstantiatedParameters in
 LambdaScopeForCallOperatorInstantiationRAII.

---
 clang/lib/Sema/SemaLambda.cpp   | 37 +
 clang/test/SemaTemplate/concepts-lambda.cpp | 14 
 2 files changed, 37 insertions(+), 14 deletions(-)

diff --git a/clang/lib/Sema/SemaLambda.cpp b/clang/lib/Sema/SemaLambda.cpp
index ca9c7cb9faadf..b6344f53861f4 100644
--- a/clang/lib/Sema/SemaLambda.cpp
+++ b/clang/lib/Sema/SemaLambda.cpp
@@ -2379,23 +2379,32 @@ Sema::LambdaScopeForCallOperatorInstantiationRAII::
 
   SemaRef.RebuildLambdaScopeInfo(cast(FD));
 
-  FunctionDecl *Pattern = getPatternFunctionDecl(FD);
-  if (Pattern) {
-SemaRef.addInstantiatedCapturesToScope(FD, Pattern, Scope, MLTAL);
+  FunctionDecl *FDPattern = getPatternFunctionDecl(FD);
+  if (!FDPattern)
+return;
 
-FunctionDecl *ParentFD = FD;
-while (ShouldAddDeclsFromParentScope) {
+  SemaRef.addInstantiatedCapturesToScope(FD, FDPattern, Scope, MLTAL);
 
-  ParentFD =
-  dyn_cast(getLambdaAwareParentOfDeclContext(ParentFD));
-  Pattern =
-  dyn_cast(getLambdaAwareParentOfDeclContext(Pattern));
+  if (!ShouldAddDeclsFromParentScope)
+return;
 
-  if (!ParentFD || !Pattern)
-break;
+  llvm::SmallVector, 4>
+  ParentInstantiations;
+  std::pair Current = {FDPattern, FD};
+  while (true) {
+Current.first = dyn_cast(
+getLambdaAwareParentOfDeclContext(Current.first));
+Current.second = dyn_cast(
+getLambdaAwareParentOfDeclContext(Current.second));
 
-  SemaRef.addInstantiatedParametersToScope(ParentFD, Pattern, Scope, 
MLTAL);
-  SemaRef.addInstantiatedLocalVarsToScope(ParentFD, Pattern, Scope);
-}
+if (!Current.first || !Current.second)
+  break;
+
+ParentInstantiations.push_back(Current);
+  }
+
+  for (const auto &[Pattern, Inst] : llvm::reverse(ParentInstantiations)) {
+SemaRef.addInstantiatedParametersToScope(Inst, Pattern, Scope, MLTAL);
+SemaRef.addInstantiatedLocalVarsToScope(Inst, Pattern, Scope);
   }
 }
diff --git a/clang/test/SemaTemplate/concepts-lambda.cpp 
b/clang/test/SemaTemplate/concepts-lambda.cpp
index 280be71284f97..252ef08549a48 100644
--- a/clang/test/SemaTemplate/concepts-lambda.cpp
+++ b/clang/test/SemaTemplate/concepts-lambda.cpp
@@ -237,3 +237,17 @@ concept D = []() { return true; }();
 D auto x = 0;
 
 } // namespace GH93821
+
+namespace dependent_param_concept {
+template  void sink(Ts...) {}
+void dependent_param() {
+  auto L = [](auto... x) {
+return [](decltype(x)... y) {
+  return [](int z)
+requires requires { sink(y..., z); }
+  {};
+};
+  };
+  L(0, 1)(1, 2)(1);
+}
+} // namespace dependent_param_concept

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


[clang] [Clang] Prevent null pointer dereference in designated initializer check (PR #97220)

2024-06-30 Thread via cfe-commits

https://github.com/smanna12 created 
https://github.com/llvm/llvm-project/pull/97220

This patch adds a null check for the current method declaration before 
attempting to determine if it is a designated initializer.

This prevents a potential null pointer dereference when `getCurMethodDecl()` 
returns nullptr, reported by static analyzer tool in 
clang::SemaObjC::BuildInstanceMessage().

>From 63f45c952ff8ab7df261a150355a34267e4a645c Mon Sep 17 00:00:00 2001
From: "Manna, Soumi" 
Date: Sun, 30 Jun 2024 08:40:27 -0700
Subject: [PATCH] [Clang] Prevent null pointer dereference in designated
 initializer check

This patch adds a null check for the current method declaration before
attempting to determine if it is a designated initializer.

This prevents a potential null pointer dereference when `getCurMethodDecl()`
returns nullptr, reported by static analyzer tool in 
clang::SemaObjC::BuildInstanceMessage().
---
 clang/lib/Sema/SemaExprObjC.cpp | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Sema/SemaExprObjC.cpp b/clang/lib/Sema/SemaExprObjC.cpp
index 7ccecf055feed..05aa30e16ed8e 100644
--- a/clang/lib/Sema/SemaExprObjC.cpp
+++ b/clang/lib/Sema/SemaExprObjC.cpp
@@ -3206,9 +3206,11 @@ ExprResult SemaObjC::BuildInstanceMessage(
 }
 if (!isDesignatedInitChain) {
   const ObjCMethodDecl *InitMethod = nullptr;
+  auto *CurMD = SemaRef.getCurMethodDecl();
+  if (!CurMD)
+return nullptr;
   bool isDesignated =
-  SemaRef.getCurMethodDecl()->isDesignatedInitializerForTheInterface(
-  &InitMethod);
+  CurMD->isDesignatedInitializerForTheInterface(&InitMethod);
   assert(isDesignated && InitMethod);
   (void)isDesignated;
   Diag(SelLoc, SuperLoc.isValid() ?

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


[clang] [Clang] Prevent null pointer dereference in designated initializer check (PR #97220)

2024-06-30 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (smanna12)


Changes

This patch adds a null check for the current method declaration before 
attempting to determine if it is a designated initializer.

This prevents a potential null pointer dereference when `getCurMethodDecl()` 
returns nullptr, reported by static analyzer tool in 
clang::SemaObjC::BuildInstanceMessage().

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


1 Files Affected:

- (modified) clang/lib/Sema/SemaExprObjC.cpp (+4-2) 


``diff
diff --git a/clang/lib/Sema/SemaExprObjC.cpp b/clang/lib/Sema/SemaExprObjC.cpp
index 7ccecf055feed..05aa30e16ed8e 100644
--- a/clang/lib/Sema/SemaExprObjC.cpp
+++ b/clang/lib/Sema/SemaExprObjC.cpp
@@ -3206,9 +3206,11 @@ ExprResult SemaObjC::BuildInstanceMessage(
 }
 if (!isDesignatedInitChain) {
   const ObjCMethodDecl *InitMethod = nullptr;
+  auto *CurMD = SemaRef.getCurMethodDecl();
+  if (!CurMD)
+return nullptr;
   bool isDesignated =
-  SemaRef.getCurMethodDecl()->isDesignatedInitializerForTheInterface(
-  &InitMethod);
+  CurMD->isDesignatedInitializerForTheInterface(&InitMethod);
   assert(isDesignated && InitMethod);
   (void)isDesignated;
   Diag(SelLoc, SuperLoc.isValid() ?

``




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


[clang-tools-extra] [clang-doc] switched from using relative to absolute paths (PR #93281)

2024-06-30 Thread Paul Kirth via cfe-commits


@@ -0,0 +1,7 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "CHECK: var RootPath = \"%/t/docs\";" > %t/check.txt
+// RUN: cp "%s" "%t/test.cpp"

ilovepi wrote:

I see you're trying to work around the path inconsistency issues, but that's 
just an end-around our testing practices, and we shouldn't be doing it. Tests 
server as documentation, and generating a test w/ `CHECK` lines undermines that 
pretty significantly. IMO if the test isn't useful w/ the regular expression, 
it isn't useful. As it stands I also can't reason about how the behavior here 
is changing as a result of this patch, so I don' think this is a particularly 
good/useful check.

If possible, it would be good to add these tests in another patch(e.g. 
pre-commit them testing the current behavior), and then update these to make 
them pass. That requires either stacking the PR using 
[spr](https://github.com/spacedentist/spr), or just managing the github PRs 
carefully yourself. Either is fine.

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


[clang-tools-extra] [clang-doc] switched from using relative to absolute paths (PR #93281)

2024-06-30 Thread Paul Kirth via cfe-commits


@@ -0,0 +1,7 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "CHECK: var RootPath = \"%/t/docs\";" > %t/check.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --format=html --executor=standalone -p %t %t/test.cpp 
--output=%t/docs
+// RUN: FileCheck %t/check.txt -input-file=%t/docs/index_json.js

ilovepi wrote:

```suggestion
// RUN: FileCheck %s -input-file=%t/index_json.js --check-prefix=SOME_PREFIX
```

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


[clang-tools-extra] [clang-doc] switched from using relative to absolute paths (PR #93281)

2024-06-30 Thread Paul Kirth via cfe-commits


@@ -0,0 +1,7 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "CHECK: var RootPath = \"%/t/docs\";" > %t/check.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --format=html --executor=standalone -p %t %t/test.cpp 
--output=%t/docs

ilovepi wrote:

```suggestion
// RUN: clang-doc --format=html --executor=standalone  %s --output=%t
```
I don't think you need `-p`, and I don't see a good reason why you need a 
subdirectory for `docs`.

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


[clang-tools-extra] [clang-doc] switched from using relative to absolute paths (PR #93281)

2024-06-30 Thread Paul Kirth via cfe-commits


@@ -7,6 +7,7 @@
 // RUN: FileCheck %s -input-file=%t/docs/GlobalNamespace/Rectangle.html 
-check-prefix=HTML-RECTANGLE
 // RUN: FileCheck %s -input-file=%t/docs/GlobalNamespace/Circle.html 
-check-prefix=HTML-CIRCLE
 
+// JSON-INDEX: var RootPath = "{{.*}}";

ilovepi wrote:

Oh, then I'm not 100% sure we want to replace all the `\` w/ `/`. I know you 
mentioned browser behavior, but I'm not 100% certain that's a great motivation. 
When I thought it was a URL, there's obviously no issue, but, for a file system 
path, I'm hesitant to say with confidence that there's no downside.

Also, given the test updates, IDK if this check is particularly useful. I don't 
see much difference in the check as is, and just 
```
// JSON-INDEX: var RootPath =
```

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


[clang-tools-extra] a9b1e80 - [clang-doc] add async loading (#93276)

2024-06-30 Thread via cfe-commits

Author: PeterChou1
Date: 2024-06-30T08:52:36-07:00
New Revision: a9b1e80acbb3249a245a7bbd8c8f89607bcad954

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

LOG: [clang-doc] add async loading (#93276)

Fixes https://github.com/llvm/llvm-project/issues/93273

This patch changes the way clang-doc loads html indexes. Previously
clang-doc loaded the index via an index_json.js file which uses
JSON.parse to parse the file. This patches changes that to use an async
function called LoadIndex which enables asynchronous loading making the
initial page load not be blocked by loading a large JavaScript object.

Added: 


Modified: 
clang-tools-extra/clang-doc/HTMLGenerator.cpp
clang-tools-extra/clang-doc/assets/index.js
clang-tools-extra/test/clang-doc/basic-project.test

Removed: 




diff  --git a/clang-tools-extra/clang-doc/HTMLGenerator.cpp 
b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
index 4c72b329507d3..b5da17564c2e0 100644
--- a/clang-tools-extra/clang-doc/HTMLGenerator.cpp
+++ b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
@@ -993,9 +993,9 @@ static llvm::Error serializeIndex(ClangDocContext &CDCtx) {
   });
 });
   };
-  OS << "var JsonIndex = `\n";
+  OS << "async function LoadIndex() {\nreturn";
   IndexToJSON(CDCtx.Idx);
-  OS << "`;\n";
+  OS << ";\n}";
   return llvm::Error::success();
 }
 

diff  --git a/clang-tools-extra/clang-doc/assets/index.js 
b/clang-tools-extra/clang-doc/assets/index.js
index a5ac90f2e06e7..49818763a4393 100644
--- a/clang-tools-extra/clang-doc/assets/index.js
+++ b/clang-tools-extra/clang-doc/assets/index.js
@@ -80,8 +80,8 @@ function createIndex(Index) {
 
 // Runs after DOM loads
 document.addEventListener("DOMContentLoaded", function() {
-  // JsonIndex is a variable from another file that contains the index
-  // in JSON format
-  var Index = JSON.parse(JsonIndex);
-  createIndex(Index);
+  // LoadIndex is an asynchronous function that will be generated clang-doc.
+  // It ensures that the function call will not block as soon the page loads,
+  // since the index object are often huge and can contain thousands of lines.
+  LoadIndex().then((Index) => { createIndex(Index); });
 });

diff  --git a/clang-tools-extra/test/clang-doc/basic-project.test 
b/clang-tools-extra/test/clang-doc/basic-project.test
index 3118c20495987..bab5f8e1761bc 100644
--- a/clang-tools-extra/test/clang-doc/basic-project.test
+++ b/clang-tools-extra/test/clang-doc/basic-project.test
@@ -7,8 +7,8 @@
 // RUN: FileCheck %s -input-file=%t/docs/GlobalNamespace/Rectangle.html 
-check-prefix=HTML-RECTANGLE
 // RUN: FileCheck %s -input-file=%t/docs/GlobalNamespace/Circle.html 
-check-prefix=HTML-CIRCLE
 
-// JSON-INDEX: var JsonIndex = `
-// JSON-INDEX-NEXT: {
+// JSON-INDEX: async function LoadIndex() {
+// JSON-INDEX-NEXT: return{
 // JSON-INDEX-NEXT:   "USR": "{{([0-9A-F]{40})}}",
 // JSON-INDEX-NEXT:   "Name": "",
 // JSON-INDEX-NEXT:   "RefType": "default",
@@ -51,7 +51,8 @@
 // JSON-INDEX-NEXT:   ]
 // JSON-INDEX-NEXT: }
 // JSON-INDEX-NEXT:   ]
-// JSON-INDEX-NEXT: }`;
+// JSON-INDEX-NEXT: };
+// JSON-INDEX-NEXT: }
 
 // HTML-SHAPE: 
 // HTML-SHAPE-NEXT: 



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


[clang-tools-extra] [clang-doc] add async loading (PR #93276)

2024-06-30 Thread Paul Kirth via cfe-commits

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


[clang-tools-extra] [clang-doc] add async loading (PR #93276)

2024-06-30 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `llvm-clang-x86_64-sie-win` 
running on `sie-win-worker` while building `clang-tools-extra` at step 4 
"clean-build-dir".

Full details are available at: 
https://lab.llvm.org/buildbot/#/builders/46/builds/863

Here is the relevant piece of the build log for the reference:
```
Step 4 (clean-build-dir) failure: Delete failed. (failure)
Step 6 (build-unified-tree) failure: build (failure)
...
[663/4660] Building IntrinsicsHexagon.h...
[664/4660] Building DiagnosticSerializationKinds.inc...
[665/4660] Building IntrinsicsDirectX.h...
[666/4660] Building DiagnosticGroups.inc...
[667/4660] Building arm_mve_builtins.inc...
[668/4660] Building IntrinsicsPowerPC.h...
[669/4660] Building arm_fp16.inc...
[670/4660] Building IntrinsicsR600.h...
[671/4660] Building AttrList.inc...
[672/4660] Linking CXX executable bin\FileCheck.exe
FAILED: bin/FileCheck.exe 
cmd.exe /C "cd . && "C:\Program Files (x86)\Microsoft Visual 
Studio\2019\BuildTools\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe"
 -E vs_link_exe --intdir=utils\FileCheck\CMakeFiles\FileCheck.dir 
--rc=C:\PROGRA~2\WI3CF2~1\10\bin\100190~1.0\x64\rc.exe 
--mt=C:\PROGRA~2\WI3CF2~1\10\bin\100190~1.0\x64\mt.exe --manifests  -- 
C:\PROGRA~2\MICROS~1\2019\BUILDT~1\VC\Tools\MSVC\1429~1.301\bin\HostX64\x64\link.exe
 /nologo utils\FileCheck\CMakeFiles\FileCheck.dir\FileCheck.cpp.obj 
utils\FileCheck\CMakeFiles\FileCheck.dir\__\__\resources\windows_version_resource.rc.res
  /out:bin\FileCheck.exe /implib:lib\FileCheck.lib /pdb:bin\FileCheck.pdb 
/version:0.0 /machine:x64 /STACK:1000 /INCREMENTAL:NO /subsystem:console  
lib\LLVMFileCheck.lib  lib\LLVMSupport.lib  psapi.lib  shell32.lib  ole32.lib  
uuid.lib  advapi32.lib  ws2_32.lib  ntdll.lib  delayimp.lib  
-delayload:shell32.dll  -delayload:ole32.dll  lib\LLVMDemangle.lib  
kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib 
oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && cd ."
LINK: command 
"C:\PROGRA~2\MICROS~1\2019\BUILDT~1\VC\Tools\MSVC\1429~1.301\bin\HostX64\x64\link.exe
 /nologo utils\FileCheck\CMakeFiles\FileCheck.dir\FileCheck.cpp.obj 
utils\FileCheck\CMakeFiles\FileCheck.dir\__\__\resources\windows_version_resource.rc.res
 /out:bin\FileCheck.exe /implib:lib\FileCheck.lib /pdb:bin\FileCheck.pdb 
/version:0.0 /machine:x64 /STACK:1000 /INCREMENTAL:NO /subsystem:console 
lib\LLVMFileCheck.lib lib\LLVMSupport.lib psapi.lib shell32.lib ole32.lib 
uuid.lib advapi32.lib ws2_32.lib ntdll.lib delayimp.lib -delayload:shell32.dll 
-delayload:ole32.dll lib\LLVMDemangle.lib kernel32.lib user32.lib gdi32.lib 
winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib 
advapi32.lib /MANIFEST /MANIFESTFILE:bin\FileCheck.exe.manifest" failed (exit 
code 1104) with the following output:
LINK : fatal error LNK1104: cannot open file 'bin\FileCheck.exe'

[673/4660] Building AttrSubMatchRulesList.inc...
[674/4660] Building IntrinsicsS390.h...
[675/4660] Building IntrinsicsRISCV.h...
[676/4660] Building riscv_vector_builtins.inc...
[677/4660] Building RegularKeywordAttrInfo.inc...
[678/4660] Building IntrinsicsWebAssembly.h...
[679/4660] Building Builtins.inc...
[680/4660] Building BuiltinsBPF.inc...
[681/4660] Building IntrinsicsSPIRV.h...
[682/4660] Building arm_neon.inc...
[683/4660] Building IntrinsicsVE.h...
[684/4660] Building arm_mve_builtin_cg.inc...
[685/4660] Building IntrinsicsX86.h...
[686/4660] Building IntrinsicsXCore.h...
[687/4660] Building arm_sme_sema_rangechecks.inc...
[688/4660] Building arm_mve_builtin_sema.inc...
[689/4660] Building arm_sve_builtin_cg.inc...
[690/4660] Building arm_cde_builtin_aliases.inc...
[691/4660] Building arm_sme_builtins_za_state.inc...
[692/4660] Building arm_sme_streaming_attrs.inc...
[693/4660] Building arm_sve_typeflags.inc...
[694/4660] Building arm_sve_sema_rangechecks.inc...
[695/4660] Building arm_sve_streaming_attrs.inc...
[696/4660] Building riscv_sifive_vector_builtin_sema.inc...
[697/4660] Building arm_sme_builtins.inc...
[698/4660] Building arm_cde_builtins.inc...
[699/4660] Building arm_cde_builtin_cg.inc...
[700/4660] Building riscv_sifive_vector_builtins.inc...
[701/4660] Building riscv_sifive_vector_builtin_cg.inc...
[702/4660] Building AttrParserStringSwitches.inc...
[703/4660] Building AttrSubMatchRulesParserStringSwitches.inc...
[704/4660] Building AttrTemplateInstantiate.inc...
[705/4660] Building AttrParsedAttrList.inc...
[706/4660] Building AttrParsedAttrKinds.inc...

```

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


[clang] [Serialization] Clear moved-from deque to ensure valid state post-move (PR #97221)

2024-06-30 Thread via cfe-commits

https://github.com/smanna12 created 
https://github.com/llvm/llvm-project/pull/97221

This patch addresses a use-after-move issue, reported by static analyzer tool, 
by clearing the `PotentiallyInterestingDecls` deque after it has been moved to 
`MaybeInterestingDecls`.

The fix ensures that the subsequent assert statement correctly checks for an 
empty state, preventing any undefined behavior in 
ASTReader::PassInterestingDeclsToConsumer().

>From fb5f36ee15bbeaf0d6d181dcf51c2847fc8babc8 Mon Sep 17 00:00:00 2001
From: "Manna, Soumi" 
Date: Sun, 30 Jun 2024 09:05:12 -0700
Subject: [PATCH] [Serialization] Clear moved-from deque to ensure valid state
 post-move

This patch addresses a use-after-move issue, reported by static analyzer
tool, by clearing the `PotentiallyInterestingDecls` deque after it has been
moved to `MaybeInterestingDecls`.

The fix ensures that the subsequent assert statement correctly checks for an
empty state, preventing any undefined behavior in 
ASTReader::PassInterestingDeclsToConsumer().
---
 clang/lib/Serialization/ASTReaderDecl.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp 
b/clang/lib/Serialization/ASTReaderDecl.cpp
index 6afb18f932e72..cf3737c5a501d 100644
--- a/clang/lib/Serialization/ASTReaderDecl.cpp
+++ b/clang/lib/Serialization/ASTReaderDecl.cpp
@@ -4215,6 +4215,7 @@ void ASTReader::PassInterestingDeclsToConsumer() {
   };
   std::deque MaybeInterestingDecls =
   std::move(PotentiallyInterestingDecls);
+  PotentiallyInterestingDecls.clear();
   assert(PotentiallyInterestingDecls.empty());
   while (!MaybeInterestingDecls.empty()) {
 Decl *D = MaybeInterestingDecls.front();

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


[clang] [Serialization] Clear moved-from deque to ensure valid state post-move (PR #97221)

2024-06-30 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-modules

Author: None (smanna12)


Changes

This patch addresses a use-after-move issue, reported by static analyzer tool, 
by clearing the `PotentiallyInterestingDecls` deque after it has been moved to 
`MaybeInterestingDecls`.

The fix ensures that the subsequent assert statement correctly checks for an 
empty state, preventing any undefined behavior in 
ASTReader::PassInterestingDeclsToConsumer().

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


1 Files Affected:

- (modified) clang/lib/Serialization/ASTReaderDecl.cpp (+1) 


``diff
diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp 
b/clang/lib/Serialization/ASTReaderDecl.cpp
index 6afb18f932e72..cf3737c5a501d 100644
--- a/clang/lib/Serialization/ASTReaderDecl.cpp
+++ b/clang/lib/Serialization/ASTReaderDecl.cpp
@@ -4215,6 +4215,7 @@ void ASTReader::PassInterestingDeclsToConsumer() {
   };
   std::deque MaybeInterestingDecls =
   std::move(PotentiallyInterestingDecls);
+  PotentiallyInterestingDecls.clear();
   assert(PotentiallyInterestingDecls.empty());
   while (!MaybeInterestingDecls.empty()) {
 Decl *D = MaybeInterestingDecls.front();

``




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


[clang] [Clang] Prevent null pointer dereference in designated initializer check (PR #97220)

2024-06-30 Thread via cfe-commits

https://github.com/smanna12 updated 
https://github.com/llvm/llvm-project/pull/97220

>From 63f45c952ff8ab7df261a150355a34267e4a645c Mon Sep 17 00:00:00 2001
From: "Manna, Soumi" 
Date: Sun, 30 Jun 2024 08:40:27 -0700
Subject: [PATCH 1/2] [Clang] Prevent null pointer dereference in designated
 initializer check

This patch adds a null check for the current method declaration before
attempting to determine if it is a designated initializer.

This prevents a potential null pointer dereference when `getCurMethodDecl()`
returns nullptr, reported by static analyzer tool in 
clang::SemaObjC::BuildInstanceMessage().
---
 clang/lib/Sema/SemaExprObjC.cpp | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Sema/SemaExprObjC.cpp b/clang/lib/Sema/SemaExprObjC.cpp
index 7ccecf055feed..05aa30e16ed8e 100644
--- a/clang/lib/Sema/SemaExprObjC.cpp
+++ b/clang/lib/Sema/SemaExprObjC.cpp
@@ -3206,9 +3206,11 @@ ExprResult SemaObjC::BuildInstanceMessage(
 }
 if (!isDesignatedInitChain) {
   const ObjCMethodDecl *InitMethod = nullptr;
+  auto *CurMD = SemaRef.getCurMethodDecl();
+  if (!CurMD)
+return nullptr;
   bool isDesignated =
-  SemaRef.getCurMethodDecl()->isDesignatedInitializerForTheInterface(
-  &InitMethod);
+  CurMD->isDesignatedInitializerForTheInterface(&InitMethod);
   assert(isDesignated && InitMethod);
   (void)isDesignated;
   Diag(SelLoc, SuperLoc.isValid() ?

>From 44c309e87d2101b554321741b1c751247a5b6478 Mon Sep 17 00:00:00 2001
From: "Manna, Soumi" 
Date: Sun, 30 Jun 2024 09:47:03 -0700
Subject: [PATCH 2/2] Fix build failure

---
 clang/lib/Sema/SemaExprObjC.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaExprObjC.cpp b/clang/lib/Sema/SemaExprObjC.cpp
index 05aa30e16ed8e..f943b5f3b5339 100644
--- a/clang/lib/Sema/SemaExprObjC.cpp
+++ b/clang/lib/Sema/SemaExprObjC.cpp
@@ -3208,7 +3208,7 @@ ExprResult SemaObjC::BuildInstanceMessage(
   const ObjCMethodDecl *InitMethod = nullptr;
   auto *CurMD = SemaRef.getCurMethodDecl();
   if (!CurMD)
-return nullptr;
+return ExprResult((Expr*)nullptr);
   bool isDesignated =
   CurMD->isDesignatedInitializerForTheInterface(&InitMethod);
   assert(isDesignated && InitMethod);

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


[clang] [Clang] Prevent null pointer dereference in designated initializer check (PR #97220)

2024-06-30 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 2051736f7bc3fb1a8daaeecc854f93604a590aba 
44c309e87d2101b554321741b1c751247a5b6478 -- clang/lib/Sema/SemaExprObjC.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Sema/SemaExprObjC.cpp b/clang/lib/Sema/SemaExprObjC.cpp
index f943b5f3b5..80e35f79a1 100644
--- a/clang/lib/Sema/SemaExprObjC.cpp
+++ b/clang/lib/Sema/SemaExprObjC.cpp
@@ -3208,7 +3208,7 @@ ExprResult SemaObjC::BuildInstanceMessage(
   const ObjCMethodDecl *InitMethod = nullptr;
   auto *CurMD = SemaRef.getCurMethodDecl();
   if (!CurMD)
-return ExprResult((Expr*)nullptr);
+return ExprResult((Expr *)nullptr);
   bool isDesignated =
   CurMD->isDesignatedInitializerForTheInterface(&InitMethod);
   assert(isDesignated && InitMethod);

``




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


[clang] [Clang] Prevent null pointer dereference in designated initializer check (PR #97220)

2024-06-30 Thread via cfe-commits

https://github.com/smanna12 updated 
https://github.com/llvm/llvm-project/pull/97220

>From 63f45c952ff8ab7df261a150355a34267e4a645c Mon Sep 17 00:00:00 2001
From: "Manna, Soumi" 
Date: Sun, 30 Jun 2024 08:40:27 -0700
Subject: [PATCH 1/3] [Clang] Prevent null pointer dereference in designated
 initializer check

This patch adds a null check for the current method declaration before
attempting to determine if it is a designated initializer.

This prevents a potential null pointer dereference when `getCurMethodDecl()`
returns nullptr, reported by static analyzer tool in 
clang::SemaObjC::BuildInstanceMessage().
---
 clang/lib/Sema/SemaExprObjC.cpp | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Sema/SemaExprObjC.cpp b/clang/lib/Sema/SemaExprObjC.cpp
index 7ccecf055feed..05aa30e16ed8e 100644
--- a/clang/lib/Sema/SemaExprObjC.cpp
+++ b/clang/lib/Sema/SemaExprObjC.cpp
@@ -3206,9 +3206,11 @@ ExprResult SemaObjC::BuildInstanceMessage(
 }
 if (!isDesignatedInitChain) {
   const ObjCMethodDecl *InitMethod = nullptr;
+  auto *CurMD = SemaRef.getCurMethodDecl();
+  if (!CurMD)
+return nullptr;
   bool isDesignated =
-  SemaRef.getCurMethodDecl()->isDesignatedInitializerForTheInterface(
-  &InitMethod);
+  CurMD->isDesignatedInitializerForTheInterface(&InitMethod);
   assert(isDesignated && InitMethod);
   (void)isDesignated;
   Diag(SelLoc, SuperLoc.isValid() ?

>From 44c309e87d2101b554321741b1c751247a5b6478 Mon Sep 17 00:00:00 2001
From: "Manna, Soumi" 
Date: Sun, 30 Jun 2024 09:47:03 -0700
Subject: [PATCH 2/3] Fix build failure

---
 clang/lib/Sema/SemaExprObjC.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaExprObjC.cpp b/clang/lib/Sema/SemaExprObjC.cpp
index 05aa30e16ed8e..f943b5f3b5339 100644
--- a/clang/lib/Sema/SemaExprObjC.cpp
+++ b/clang/lib/Sema/SemaExprObjC.cpp
@@ -3208,7 +3208,7 @@ ExprResult SemaObjC::BuildInstanceMessage(
   const ObjCMethodDecl *InitMethod = nullptr;
   auto *CurMD = SemaRef.getCurMethodDecl();
   if (!CurMD)
-return nullptr;
+return ExprResult((Expr*)nullptr);
   bool isDesignated =
   CurMD->isDesignatedInitializerForTheInterface(&InitMethod);
   assert(isDesignated && InitMethod);

>From ca4a91f41048e30dc373a40a019216813df0e7c0 Mon Sep 17 00:00:00 2001
From: "Manna, Soumi" 
Date: Sun, 30 Jun 2024 10:00:26 -0700
Subject: [PATCH 3/3] Fix Clang format errors

---
 clang/lib/Sema/SemaExprObjC.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaExprObjC.cpp b/clang/lib/Sema/SemaExprObjC.cpp
index f943b5f3b5339..80e35f79a172d 100644
--- a/clang/lib/Sema/SemaExprObjC.cpp
+++ b/clang/lib/Sema/SemaExprObjC.cpp
@@ -3208,7 +3208,7 @@ ExprResult SemaObjC::BuildInstanceMessage(
   const ObjCMethodDecl *InitMethod = nullptr;
   auto *CurMD = SemaRef.getCurMethodDecl();
   if (!CurMD)
-return ExprResult((Expr*)nullptr);
+return ExprResult((Expr *)nullptr);
   bool isDesignated =
   CurMD->isDesignatedInitializerForTheInterface(&InitMethod);
   assert(isDesignated && InitMethod);

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


[clang] [NFC] [Clang] Some core issues have changed status from tentatively ready -> ready / review (PR #97200)

2024-06-30 Thread Mital Ashok via cfe-commits

https://github.com/MitalAshok updated 
https://github.com/llvm/llvm-project/pull/97200

>From 0dea95701ca4dfca9b7d0bd889003fc35aa3017e Mon Sep 17 00:00:00 2001
From: Mital Ashok 
Date: Sun, 30 Jun 2024 10:39:15 +0100
Subject: [PATCH 1/9] [NFC] [Clang] Some core issues have changed status from
 tentatively ready -> ready / review

---
 clang/test/CXX/drs/cwg25xx.cpp |   2 +-
 clang/test/CXX/drs/cwg28xx.cpp |  16 ++--
 clang/www/cxx_dr_status.html   | 130 +++--
 clang/www/make_cxx_dr_status   |   6 +-
 4 files changed, 104 insertions(+), 50 deletions(-)

diff --git a/clang/test/CXX/drs/cwg25xx.cpp b/clang/test/CXX/drs/cwg25xx.cpp
index 0934f0cc19c6a..5f8a058f8157a 100644
--- a/clang/test/CXX/drs/cwg25xx.cpp
+++ b/clang/test/CXX/drs/cwg25xx.cpp
@@ -139,7 +139,7 @@ struct D3 : B {
 #endif
 
 #if __cplusplus >= 202302L
-namespace cwg2561 { // cwg2561: no tentatively ready 2024-03-18
+namespace cwg2561 { // cwg2561: no ready 2024-03-18
 struct C {
 constexpr C(auto) { }
 };
diff --git a/clang/test/CXX/drs/cwg28xx.cpp b/clang/test/CXX/drs/cwg28xx.cpp
index c77bd433d8e21..524e67b52de51 100644
--- a/clang/test/CXX/drs/cwg28xx.cpp
+++ b/clang/test/CXX/drs/cwg28xx.cpp
@@ -30,7 +30,7 @@ using U2 = decltype(&main);
 #endif
 } // namespace cwg2811
 
-namespace cwg2819 { // cwg2819: 19 tentatively ready 2023-12-01
+namespace cwg2819 { // cwg2819: 19 ready 2023-12-01
 #if __cpp_constexpr >= 202306L
   constexpr void* p = nullptr;
   constexpr int* q = static_cast(p);
@@ -111,7 +111,7 @@ struct D : N::B {
 #endif
 } // namespace cwg2857
 
-namespace cwg2858 { // cwg2858: 19 tentatively ready 2024-04-05
+namespace cwg2858 { // cwg2858: 19 ready 2024-04-05
 
 #if __cplusplus > 202302L
 
@@ -134,7 +134,7 @@ struct A {
 
 } // namespace cwg2858
 
-namespace cwg2877 { // cwg2877: 19 tentatively ready 2024-05-31
+namespace cwg2877 { // cwg2877: 19 ready 2024-05-31
 #if __cplusplus >= 202002L
 enum E { x };
 void f() {
@@ -150,7 +150,7 @@ void g() {
 #endif
 } // namespace cwg2877
 
-namespace cwg2881 { // cwg2881: 19 tentatively ready 2024-04-19
+namespace cwg2881 { // cwg2881: 19 ready 2024-04-19
 
 #if __cplusplus >= 202302L
 
@@ -220,7 +220,7 @@ void f() {
 
 } // namespace cwg2881
 
-namespace cwg2882 { // cwg2882: 2.7 tentatively ready 2024-05-31
+namespace cwg2882 { // cwg2882: 2.7 ready 2024-05-31
 struct C {
   operator void() = delete;
   // expected-warning@-1 {{conversion function converting 'cwg2882::C' to 
'void' will never be used}}
@@ -232,7 +232,7 @@ void f(C c) {
 }
 } // namespace cwg2882
 
-namespace cwg2883 { // cwg2883: no tentatively ready 2024-05-31
+namespace cwg2883 { // cwg2883: no ready 2024-05-31
 #if __cplusplus >= 201103L
 void f() {
   int x;
@@ -257,7 +257,7 @@ void g() {
 #endif
 } // namespace cwg2883
 
-namespace cwg2885 { // cwg2885: 16 tentatively ready 2024-05-31
+namespace cwg2885 { // cwg2885: 16 review 2024-05-31
 #if __cplusplus >= 202002L
 template 
 struct A {
@@ -271,7 +271,7 @@ static_assert(!__is_trivially_constructible(B));
 #endif
 } // namespace cwg2885
 
-namespace cwg2886 { // cwg2886: 9 tentatively ready 2024-05-31
+namespace cwg2886 { // cwg2886: 9 ready 2024-05-31
 #if __cplusplus >= 201103L
 struct C {
   C() = default;
diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index 937f67981e296..64b361976a5a5 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -1442,7 +1442,7 @@ C++ defect report implementation 
status
   
   
 https://cplusplus.github.io/CWG/issues/233.html";>233
-tentatively ready
+ready
 References vs pointers in UDC overload resolution
 Not resolved
   
@@ -7329,11 +7329,11 @@ C++ defect report implementation 
status
 Overloading member function templates based on dependent return 
type
 Unknown
   
-  
+  
 https://cplusplus.github.io/CWG/issues/1253.html";>1253
-open
+C++17
 Generic non-template members
-Not resolved
+Unknown
   
   
 https://cplusplus.github.io/CWG/issues/1254.html";>1254
@@ -12677,7 +12677,7 @@ C++ defect report implementation 
status
   
   
 https://cplusplus.github.io/CWG/issues/2144.html";>2144
-tentatively ready
+ready
 Function/variable declaration ambiguity
 Not resolved
   
@@ -15179,7 +15179,7 @@ C++ defect report implementation 
status
   
   
 https://cplusplus.github.io/CWG/issues/2561.html";>2561
-tentatively ready
+ready
 Conversion to function pointer for lambda with explicit object 
parameter
 Not Resolved*
   
@@ -15341,7 +15341,7 @@ C++ defect report implementation 
status
   
   
 https://cplusplus.github.io/CWG/issues/2588.html";>2588
-tentatively ready
+ready
 friend declarations and module linkage
 Not resolved
   
@@ -15541,7 +15541,7 @@ C++ defect report implementation 
status
 https://cplusplus.github.io/CWG/issues/2621.html";>2621
 C++23
 Kind of lookup for using enum declarations
-Superseded by 2877

[clang] [compiler-rt] [llvm] [TypeProf][InstrFDO]Implement more efficient comparison sequence for indirect-call-promotion with vtable profiles. (PR #81442)

2024-06-30 Thread Mingming Liu via cfe-commits

minglotus-6 wrote:

Fixing https://lab.llvm.org/buildbot/#/builders/95/builds/672 in 
https://github.com/llvm/llvm-project/pull/97228

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


[clang] [llvm] [APFloat] Add support for f8E4M3 IEEE 754 type (PR #97179)

2024-06-30 Thread Alexander Pivovarov via cfe-commits


@@ -136,6 +136,7 @@ static constexpr fltSemantics semIEEEquad = {16383, -16382, 
113, 128};
 static constexpr fltSemantics semFloat8E5M2 = {15, -14, 3, 8};
 static constexpr fltSemantics semFloat8E5M2FNUZ = {
 15, -15, 3, 8, fltNonfiniteBehavior::NanOnly, 
fltNanEncoding::NegativeZero};
+static constexpr fltSemantics semFloat8E4M3 = {7, -6, 4, 8};

apivovarov wrote:

`f8E4M3` type follows IEEE 754 convention:
- Exponent bias: 7
- Maximum stored exponent value: 14 (binary 1110)
- Maximum unbiased exponent value: 14 - 7 = 7
- Minimum stored exponent value: 1 (binary 0001)
- Minimum unbiased exponent value: 1 − 7 = −6
- Precision specifies the total number of bits used for the significand 
(mantisa), including implicit leading integer bit = 3 + 1 = 4

`fltSemantics semFloat8E4M3 = {7, -6, 4, 8};`:
- maxExponent = 7
- minExponent = -6
- precision = 4
- sizeInBits = 8
- nonFiniteBehavior = fltNonfiniteBehavior::IEEE754
- nanEncoding = fltNanEncoding::IEEE

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


[clang] [Driver] Add support for -export-dynamic which can match GCC behavior. (PR #72781)

2024-06-30 Thread Eli Schwartz via cfe-commits

eli-schwartz wrote:

The `-export-dynamic` flag is supported by libtool, not gcc and not binutils 
ld. If passed to libtool, it will cause `$export_dynamic_flag_spec` as 
conditionally per-platform defined in a GNU autotools configure script to be 
evaluated and passed to the compiler:
- for gcc, this is `$wl--export-dynamic`
- for cygwin, this is `$wl--export-all-symbols`
- for interix, this is `$wl-E`
- for AIX, this is `$wl-bexpall`

Anyone passing libtool flags to gcc has incorrectly and erroneously ported 
their project away from libtool, or else cargo-culted flags that get 
misinterpreted. Simply do not do so, and do not patch new linkers to implement 
the libtool interface out of the mistaken belief that it is a linker interface.

(Or do implement libtool within clang, if you would like to. However if you do 
so, please do so intentionally, rather than accidentally.)

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


[clang] [llvm] [APFloat] Add support for f8E4M3 IEEE 754 type (PR #97179)

2024-06-30 Thread Alexander Pivovarov via cfe-commits

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


[clang] [llvm] [APFloat] Add support for f8E4M3 IEEE 754 type (PR #97179)

2024-06-30 Thread Alexander Pivovarov via cfe-commits

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


[clang] [llvm] [mlir] [MLIR] Add f8E4M3 IEEE 754 type (PR #97118)

2024-06-30 Thread Alexander Pivovarov via cfe-commits

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


[clang] [llvm] [mlir] [MLIR] Add f8E4M3 IEEE 754 type (PR #97118)

2024-06-30 Thread Alexander Pivovarov via cfe-commits

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


[clang] [llvm] [mlir] [MLIR] Add f8E4M3 IEEE 754 type (PR #97118)

2024-06-30 Thread Alexander Pivovarov via cfe-commits

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


[clang] [llvm] [mlir] [MLIR] Add f8E4M3 IEEE 754 type (PR #97118)

2024-06-30 Thread Alexander Pivovarov via cfe-commits

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


[clang] [llvm] [APFloat] Add support for f8E4M3 IEEE 754 type (PR #97179)

2024-06-30 Thread Alexander Pivovarov via cfe-commits

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


[libc] [libunwind] Enough to get `libc` to build `clang` (PR #97231)

2024-06-30 Thread Izaak Schroeder via cfe-commits

https://github.com/izaakschroeder created 
https://github.com/llvm/llvm-project/pull/97231

Companion to https://github.com/llvm/llvm-project/issues/97191

>From 31dc769c1866a4a0100dde0a3743c215a9a5f5eb Mon Sep 17 00:00:00 2001
From: Izaak Schroeder 
Date: Sun, 30 Jun 2024 13:33:16 -0700
Subject: [PATCH 1/2] [libc]: add missing aarch64 headers

---
 libc/config/linux/aarch64/entrypoints.txt | 3 +++
 libc/config/linux/aarch64/headers.txt | 6 ++
 2 files changed, 9 insertions(+)

diff --git a/libc/config/linux/aarch64/entrypoints.txt 
b/libc/config/linux/aarch64/entrypoints.txt
index 8a26536cea9a0..b59400db81fed 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -308,6 +308,9 @@ set(TARGET_LIBC_ENTRYPOINTS
 libc.src.unistd.unlink
 libc.src.unistd.unlinkat
 libc.src.unistd.write
+
+# XXX
+libc.src.assert.__assert_fail
 )
 
 set(TARGET_LIBM_ENTRYPOINTS
diff --git a/libc/config/linux/aarch64/headers.txt 
b/libc/config/linux/aarch64/headers.txt
index 7d25877cefcc8..ed126d6128871 100644
--- a/libc/config/linux/aarch64/headers.txt
+++ b/libc/config/linux/aarch64/headers.txt
@@ -31,4 +31,10 @@ set(TARGET_PUBLIC_HEADERS
 libc.include.sys_ioctl
 # Disabled due to epoll_wait syscalls not being available on this platform.
 # libc.include.sys_epoll
+
+# XXX
+libc.include.sys_auxv
+libc.include.fcntl
+libc.include.sched
+libc.include.sys_stat
 )

>From a5f8ee220c088a39d9b4bf60986166e83ffafffa Mon Sep 17 00:00:00 2001
From: Izaak Schroeder 
Date: Sun, 30 Jun 2024 13:33:38 -0700
Subject: [PATCH 2/2] [libunwind]: remove needless `sys/uio.h`

No reference to `readv` or `writev`.
---
 libunwind/src/UnwindCursor.hpp | 1 -
 1 file changed, 1 deletion(-)

diff --git a/libunwind/src/UnwindCursor.hpp b/libunwind/src/UnwindCursor.hpp
index 66fe8e2a32cca..677e842d8a22b 100644
--- a/libunwind/src/UnwindCursor.hpp
+++ b/libunwind/src/UnwindCursor.hpp
@@ -36,7 +36,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #define _LIBUNWIND_CHECK_LINUX_SIGRETURN 1
 #endif

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


[libc] [libunwind] [WIP] Enough to get `libc` to build `clang` (PR #97231)

2024-06-30 Thread Izaak Schroeder via cfe-commits

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


[clang] [clang] WIP: Warn on mismatched RequiresCapability attributes (PR #67520)

2024-06-30 Thread Aaron Puchert via cfe-commits

aaronpuchert wrote:

Doesn't this fit better in `Sema/SemaDeclAttr.cpp`? That's where we're checking 
the attributes themselves and whether they make sense on a declaration. This 
would seem like a good place to check against previous declarations. Though to 
be fair, I don't know how late the late-parsed attributes are parsed, is that 
really at the end of the file?

The analysis in `Analysis/ThreadSafety.cpp` is based on the CFG of a function 
definition and at least so far doesn't really care about multiple declarations. 
But if it's the only way to make it work I guess we'll have to bite the bullet.

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


[libc] [libunwind] [WIP] Enough to get `libc` to build `clang` (PR #97231)

2024-06-30 Thread Izaak Schroeder via cfe-commits

https://github.com/izaakschroeder updated 
https://github.com/llvm/llvm-project/pull/97231

>From 31dc769c1866a4a0100dde0a3743c215a9a5f5eb Mon Sep 17 00:00:00 2001
From: Izaak Schroeder 
Date: Sun, 30 Jun 2024 13:33:16 -0700
Subject: [PATCH 1/3] [libc]: add missing aarch64 headers

---
 libc/config/linux/aarch64/entrypoints.txt | 3 +++
 libc/config/linux/aarch64/headers.txt | 6 ++
 2 files changed, 9 insertions(+)

diff --git a/libc/config/linux/aarch64/entrypoints.txt 
b/libc/config/linux/aarch64/entrypoints.txt
index 8a26536cea9a0..b59400db81fed 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -308,6 +308,9 @@ set(TARGET_LIBC_ENTRYPOINTS
 libc.src.unistd.unlink
 libc.src.unistd.unlinkat
 libc.src.unistd.write
+
+# XXX
+libc.src.assert.__assert_fail
 )
 
 set(TARGET_LIBM_ENTRYPOINTS
diff --git a/libc/config/linux/aarch64/headers.txt 
b/libc/config/linux/aarch64/headers.txt
index 7d25877cefcc8..ed126d6128871 100644
--- a/libc/config/linux/aarch64/headers.txt
+++ b/libc/config/linux/aarch64/headers.txt
@@ -31,4 +31,10 @@ set(TARGET_PUBLIC_HEADERS
 libc.include.sys_ioctl
 # Disabled due to epoll_wait syscalls not being available on this platform.
 # libc.include.sys_epoll
+
+# XXX
+libc.include.sys_auxv
+libc.include.fcntl
+libc.include.sched
+libc.include.sys_stat
 )

>From a5f8ee220c088a39d9b4bf60986166e83ffafffa Mon Sep 17 00:00:00 2001
From: Izaak Schroeder 
Date: Sun, 30 Jun 2024 13:33:38 -0700
Subject: [PATCH 2/3] [libunwind]: remove needless `sys/uio.h`

No reference to `readv` or `writev`.
---
 libunwind/src/UnwindCursor.hpp | 1 -
 1 file changed, 1 deletion(-)

diff --git a/libunwind/src/UnwindCursor.hpp b/libunwind/src/UnwindCursor.hpp
index 66fe8e2a32cca..677e842d8a22b 100644
--- a/libunwind/src/UnwindCursor.hpp
+++ b/libunwind/src/UnwindCursor.hpp
@@ -36,7 +36,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #define _LIBUNWIND_CHECK_LINUX_SIGRETURN 1
 #endif

>From 1083aecfe1be3c1cf427d4ffd2b4fad3d5129d4c Mon Sep 17 00:00:00 2001
From: Izaak Schroeder 
Date: Sun, 30 Jun 2024 13:44:52 -0700
Subject: [PATCH 3/3] [libc]: function spec for `getauxval`

---
 libc/spec/gnu_ext.td | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/libc/spec/gnu_ext.td b/libc/spec/gnu_ext.td
index 161bb4e4a0d9d..e360c766c5c54 100644
--- a/libc/spec/gnu_ext.td
+++ b/libc/spec/gnu_ext.td
@@ -237,7 +237,11 @@ def GnuExtensions : StandardSpec<"GNUExtensions"> {
   [], // Types
   [], // Enumerations
   [
-//TODO: Add getauxval here
+  FunctionSpec<
+  "getauxval",
+  RetValSpec,
+  [ArgSpec]
+  >,
   ]  // Functions
   >;
 

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


[libc] [libunwind] [WIP] Enough to get `libc` to build `clang` on `aarch64` (PR #97231)

2024-06-30 Thread Izaak Schroeder via cfe-commits

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


[clang] [clang] Disable C++14 sized deallocation by default for MinGW targets (PR #97232)

2024-06-30 Thread Martin Storsjö via cfe-commits

https://github.com/mstorsjo created 
https://github.com/llvm/llvm-project/pull/97232

This reverts 130e93cc26ca9d3ac50ec5a92e3109577ca2e702 for the MinGW target.

This avoids the issue that is discussed in
https://github.com/llvm/llvm-project/issues/96899 (and which is summarized in 
the code comment). This is intended as a temporary workaround until the issue 
is handled better within libc++.

From 424eb0ff6b32abcb4eede92c1b2f78a32d3b37a6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20Storsj=C3=B6?= 
Date: Tue, 11 Jun 2024 15:50:26 +0300
Subject: [PATCH] [clang] Disable C++14 sized deallocation by default for MinGW
 targets

This reverts 130e93cc26ca9d3ac50ec5a92e3109577ca2e702 for the
MinGW target.

This avoids the issue that is discussed in
https://github.com/llvm/llvm-project/issues/96899 (and which is
summarized in the code comment). This is intended as a temporary
workaround until the issue is handled better within libc++.
---
 clang/lib/Driver/ToolChains/MinGW.cpp | 22 +++
 .../StaticAnalyzer/CallEventTest.cpp  |  4 
 2 files changed, 26 insertions(+)

diff --git a/clang/lib/Driver/ToolChains/MinGW.cpp 
b/clang/lib/Driver/ToolChains/MinGW.cpp
index 11e81ebde7eeb..945863a4a8d63 100644
--- a/clang/lib/Driver/ToolChains/MinGW.cpp
+++ b/clang/lib/Driver/ToolChains/MinGW.cpp
@@ -726,6 +726,28 @@ void toolchains::MinGW::addClangTargetOptions(
 }
   }
 
+  // Default to not enabling sized deallocation, but let user provided options
+  // override it.
+  //
+  // If using sized deallocation, user code that invokes delete will end up
+  // calling delete(void*,size_t). If the user wanted to override the
+  // operator delete(void*), there may be a fallback operator 
delete(void*,size_t)
+  // which calls the regular operator delete(void*).
+  //
+  // However, if the C++ standard library is linked in the form of a DLL,
+  // and the fallback operator delete(void*,size_t) is within this DLL (which 
is
+  // the case for libc++ at least) it will only redirect towards the library's 
default
+  // operator delete(void*), not towards the user's provided operator 
delete(void*).
+  //
+  // This issue can be avoided, if the fallback operators are linked statically
+  // into the callers, even if the C++ standard library is linked as a DLL.
+  //
+  // This is meant as a temporary workaround until libc++ implements this 
technique,
+  // which is tracked in https://github.com/llvm/llvm-project/issues/96899.
+  if (!DriverArgs.hasArgNoClaim(options::OPT_fsized_deallocation,
+options::OPT_fno_sized_deallocation))
+CC1Args.push_back("-fno-sized-deallocation");
+
   CC1Args.push_back("-fno-use-init-array");
 
   for (auto Opt : {options::OPT_mthreads, options::OPT_mwindows,
diff --git a/clang/unittests/StaticAnalyzer/CallEventTest.cpp 
b/clang/unittests/StaticAnalyzer/CallEventTest.cpp
index 7c4132788ca7e..ba5b3e4e05ad8 100644
--- a/clang/unittests/StaticAnalyzer/CallEventTest.cpp
+++ b/clang/unittests/StaticAnalyzer/CallEventTest.cpp
@@ -76,7 +76,11 @@ TEST(CXXDeallocatorCall, SimpleDestructor) {
 }
   )",
  Diags));
+#ifdef __MINGW32__
+  EXPECT_EQ(Diags, "test.CXXDeallocator: NumArgs: 1\n");
+#else
   EXPECT_EQ(Diags, "test.CXXDeallocator: NumArgs: 2\n");
+#endif
 }
 
 } // namespace

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


[clang] [clang] Disable C++14 sized deallocation by default for MinGW targets (PR #97232)

2024-06-30 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: Martin Storsjö (mstorsjo)


Changes

This reverts 130e93cc26ca9d3ac50ec5a92e3109577ca2e702 for the MinGW target.

This avoids the issue that is discussed in
https://github.com/llvm/llvm-project/issues/96899 (and which is summarized in 
the code comment). This is intended as a temporary workaround until the issue 
is handled better within libc++.

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


2 Files Affected:

- (modified) clang/lib/Driver/ToolChains/MinGW.cpp (+22) 
- (modified) clang/unittests/StaticAnalyzer/CallEventTest.cpp (+4) 


``diff
diff --git a/clang/lib/Driver/ToolChains/MinGW.cpp 
b/clang/lib/Driver/ToolChains/MinGW.cpp
index 11e81ebde7eeb..945863a4a8d63 100644
--- a/clang/lib/Driver/ToolChains/MinGW.cpp
+++ b/clang/lib/Driver/ToolChains/MinGW.cpp
@@ -726,6 +726,28 @@ void toolchains::MinGW::addClangTargetOptions(
 }
   }
 
+  // Default to not enabling sized deallocation, but let user provided options
+  // override it.
+  //
+  // If using sized deallocation, user code that invokes delete will end up
+  // calling delete(void*,size_t). If the user wanted to override the
+  // operator delete(void*), there may be a fallback operator 
delete(void*,size_t)
+  // which calls the regular operator delete(void*).
+  //
+  // However, if the C++ standard library is linked in the form of a DLL,
+  // and the fallback operator delete(void*,size_t) is within this DLL (which 
is
+  // the case for libc++ at least) it will only redirect towards the library's 
default
+  // operator delete(void*), not towards the user's provided operator 
delete(void*).
+  //
+  // This issue can be avoided, if the fallback operators are linked statically
+  // into the callers, even if the C++ standard library is linked as a DLL.
+  //
+  // This is meant as a temporary workaround until libc++ implements this 
technique,
+  // which is tracked in https://github.com/llvm/llvm-project/issues/96899.
+  if (!DriverArgs.hasArgNoClaim(options::OPT_fsized_deallocation,
+options::OPT_fno_sized_deallocation))
+CC1Args.push_back("-fno-sized-deallocation");
+
   CC1Args.push_back("-fno-use-init-array");
 
   for (auto Opt : {options::OPT_mthreads, options::OPT_mwindows,
diff --git a/clang/unittests/StaticAnalyzer/CallEventTest.cpp 
b/clang/unittests/StaticAnalyzer/CallEventTest.cpp
index 7c4132788ca7e..ba5b3e4e05ad8 100644
--- a/clang/unittests/StaticAnalyzer/CallEventTest.cpp
+++ b/clang/unittests/StaticAnalyzer/CallEventTest.cpp
@@ -76,7 +76,11 @@ TEST(CXXDeallocatorCall, SimpleDestructor) {
 }
   )",
  Diags));
+#ifdef __MINGW32__
+  EXPECT_EQ(Diags, "test.CXXDeallocator: NumArgs: 1\n");
+#else
   EXPECT_EQ(Diags, "test.CXXDeallocator: NumArgs: 2\n");
+#endif
 }
 
 } // namespace

``




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


[clang] [clang] Disable C++14 sized deallocation by default for MinGW targets (PR #97232)

2024-06-30 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 4997af98a008e71a3df61707559710d1c2769839 
424eb0ff6b32abcb4eede92c1b2f78a32d3b37a6 -- 
clang/lib/Driver/ToolChains/MinGW.cpp 
clang/unittests/StaticAnalyzer/CallEventTest.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Driver/ToolChains/MinGW.cpp 
b/clang/lib/Driver/ToolChains/MinGW.cpp
index 945863a4a8..c81a7ed170 100644
--- a/clang/lib/Driver/ToolChains/MinGW.cpp
+++ b/clang/lib/Driver/ToolChains/MinGW.cpp
@@ -731,19 +731,21 @@ void toolchains::MinGW::addClangTargetOptions(
   //
   // If using sized deallocation, user code that invokes delete will end up
   // calling delete(void*,size_t). If the user wanted to override the
-  // operator delete(void*), there may be a fallback operator 
delete(void*,size_t)
-  // which calls the regular operator delete(void*).
+  // operator delete(void*), there may be a fallback operator
+  // delete(void*,size_t) which calls the regular operator delete(void*).
   //
   // However, if the C++ standard library is linked in the form of a DLL,
   // and the fallback operator delete(void*,size_t) is within this DLL (which 
is
-  // the case for libc++ at least) it will only redirect towards the library's 
default
-  // operator delete(void*), not towards the user's provided operator 
delete(void*).
+  // the case for libc++ at least) it will only redirect towards the library's
+  // default operator delete(void*), not towards the user's provided operator
+  // delete(void*).
   //
   // This issue can be avoided, if the fallback operators are linked statically
   // into the callers, even if the C++ standard library is linked as a DLL.
   //
-  // This is meant as a temporary workaround until libc++ implements this 
technique,
-  // which is tracked in https://github.com/llvm/llvm-project/issues/96899.
+  // This is meant as a temporary workaround until libc++ implements this
+  // technique, which is tracked in
+  // https://github.com/llvm/llvm-project/issues/96899.
   if (!DriverArgs.hasArgNoClaim(options::OPT_fsized_deallocation,
 options::OPT_fno_sized_deallocation))
 CC1Args.push_back("-fno-sized-deallocation");

``




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


[clang] [llvm] [polly] Revert "[IR] Don't include Module.h in Analysis.h (NFC) (#97023)" (PR #97129)

2024-06-30 Thread via cfe-commits

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


[clang] [clang] Disable C++14 sized deallocation by default for MinGW targets (PR #97232)

2024-06-30 Thread Martin Storsjö via cfe-commits

https://github.com/mstorsjo updated 
https://github.com/llvm/llvm-project/pull/97232

From bc68b1bc25f7a04a0ddf2188ae26ed7853913b69 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20Storsj=C3=B6?= 
Date: Tue, 11 Jun 2024 15:50:26 +0300
Subject: [PATCH] [clang] Disable C++14 sized deallocation by default for MinGW
 targets

This reverts 130e93cc26ca9d3ac50ec5a92e3109577ca2e702 for the
MinGW target.

This avoids the issue that is discussed in
https://github.com/llvm/llvm-project/issues/96899 (and which is
summarized in the code comment). This is intended as a temporary
workaround until the issue is handled better within libc++.
---
 clang/lib/Driver/ToolChains/MinGW.cpp | 24 +++
 .../StaticAnalyzer/CallEventTest.cpp  |  4 
 2 files changed, 28 insertions(+)

diff --git a/clang/lib/Driver/ToolChains/MinGW.cpp 
b/clang/lib/Driver/ToolChains/MinGW.cpp
index 11e81ebde7eeb..c81a7ed170296 100644
--- a/clang/lib/Driver/ToolChains/MinGW.cpp
+++ b/clang/lib/Driver/ToolChains/MinGW.cpp
@@ -726,6 +726,30 @@ void toolchains::MinGW::addClangTargetOptions(
 }
   }
 
+  // Default to not enabling sized deallocation, but let user provided options
+  // override it.
+  //
+  // If using sized deallocation, user code that invokes delete will end up
+  // calling delete(void*,size_t). If the user wanted to override the
+  // operator delete(void*), there may be a fallback operator
+  // delete(void*,size_t) which calls the regular operator delete(void*).
+  //
+  // However, if the C++ standard library is linked in the form of a DLL,
+  // and the fallback operator delete(void*,size_t) is within this DLL (which 
is
+  // the case for libc++ at least) it will only redirect towards the library's
+  // default operator delete(void*), not towards the user's provided operator
+  // delete(void*).
+  //
+  // This issue can be avoided, if the fallback operators are linked statically
+  // into the callers, even if the C++ standard library is linked as a DLL.
+  //
+  // This is meant as a temporary workaround until libc++ implements this
+  // technique, which is tracked in
+  // https://github.com/llvm/llvm-project/issues/96899.
+  if (!DriverArgs.hasArgNoClaim(options::OPT_fsized_deallocation,
+options::OPT_fno_sized_deallocation))
+CC1Args.push_back("-fno-sized-deallocation");
+
   CC1Args.push_back("-fno-use-init-array");
 
   for (auto Opt : {options::OPT_mthreads, options::OPT_mwindows,
diff --git a/clang/unittests/StaticAnalyzer/CallEventTest.cpp 
b/clang/unittests/StaticAnalyzer/CallEventTest.cpp
index 7c4132788ca7e..ba5b3e4e05ad8 100644
--- a/clang/unittests/StaticAnalyzer/CallEventTest.cpp
+++ b/clang/unittests/StaticAnalyzer/CallEventTest.cpp
@@ -76,7 +76,11 @@ TEST(CXXDeallocatorCall, SimpleDestructor) {
 }
   )",
  Diags));
+#ifdef __MINGW32__
+  EXPECT_EQ(Diags, "test.CXXDeallocator: NumArgs: 1\n");
+#else
   EXPECT_EQ(Diags, "test.CXXDeallocator: NumArgs: 2\n");
+#endif
 }
 
 } // namespace

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


[clang] [clang] Support --sysroot= for ${arch}-windows-msvc targets (PR #96417)

2024-06-30 Thread via cfe-commits

https://github.com/trcrsired updated 
https://github.com/llvm/llvm-project/pull/96417

>From 3a78dfee50e86f10051b681b4a6dee0071b0ca78 Mon Sep 17 00:00:00 2001
From: trcrsired 
Date: Sun, 23 Jun 2024 00:07:19 -0400
Subject: [PATCH] Support --sysroot= for ${arch}-windows-msvc targets

I think it is possible to use the same rule for msvc targets with
--target= and --sysroot=

See Repository:
https://github.com/trcrsired/windows-msvc-sysroot

Add sysroot support for msvc

MSVC.cpp needs getDriver before using D

add stl in parser for -stdlib=

Add Vcruntime to runtime list and unwind list

MSVC add default runtime lib type and default unwind lib type

add a msvc sysroot test

use %S instead of /foo

Fix test for msvc-sysroot

Also add a pesudo implementation for WebAssembly and
maybe Microsoft STL could be ported to more targets in the future

Fix the toggle of wasm that prevents -stdlib=stl passed into
---
 clang/include/clang/Driver/ToolChain.h  |   9 +-
 clang/lib/Driver/ToolChain.cpp  |   9 +
 clang/lib/Driver/ToolChains/MSVC.cpp| 248 +++-
 clang/lib/Driver/ToolChains/MSVC.h  |  24 +-
 clang/lib/Driver/ToolChains/WebAssembly.cpp |  29 +++
 clang/lib/Driver/ToolChains/WebAssembly.h   |   2 +
 clang/test/Driver/msvc-sysroot.cpp  |  81 +++
 clang/test/Driver/wasm-toolchain.cpp|  12 +
 8 files changed, 345 insertions(+), 69 deletions(-)
 create mode 100644 clang/test/Driver/msvc-sysroot.cpp

diff --git a/clang/include/clang/Driver/ToolChain.h 
b/clang/include/clang/Driver/ToolChain.h
index 1f93bd612e9b0..04535a98dd69c 100644
--- a/clang/include/clang/Driver/ToolChain.h
+++ b/clang/include/clang/Driver/ToolChain.h
@@ -95,18 +95,21 @@ class ToolChain {
 
   enum CXXStdlibType {
 CST_Libcxx,
-CST_Libstdcxx
+CST_Libstdcxx,
+CST_Stl,
   };
 
   enum RuntimeLibType {
 RLT_CompilerRT,
-RLT_Libgcc
+RLT_Libgcc,
+RLT_Vcruntime
   };
 
   enum UnwindLibType {
 UNW_None,
 UNW_CompilerRT,
-UNW_Libgcc
+UNW_Libgcc,
+UNW_Vcruntime
   };
 
   enum class UnwindTableLevel {
diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index 8f4cc47e418b5..55034bc6a8422 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -1091,6 +1091,8 @@ ToolChain::RuntimeLibType ToolChain::GetRuntimeLibType(
 runtimeLibType = ToolChain::RLT_CompilerRT;
   else if (LibName == "libgcc")
 runtimeLibType = ToolChain::RLT_Libgcc;
+  else if (LibName == "vcruntime")
+runtimeLibType = ToolChain::RLT_Vcruntime;
   else if (LibName == "platform")
 runtimeLibType = GetDefaultRuntimeLibType();
   else {
@@ -1129,6 +1131,8 @@ ToolChain::UnwindLibType ToolChain::GetUnwindLibType(
 unwindLibType = ToolChain::UNW_CompilerRT;
   } else if (LibName == "libgcc")
 unwindLibType = ToolChain::UNW_Libgcc;
+  else if (LibName == "vcruntime")
+unwindLibType = ToolChain::UNW_Vcruntime;
   else {
 if (A)
   getDriver().Diag(diag::err_drv_invalid_unwindlib_name)
@@ -1152,6 +1156,8 @@ ToolChain::CXXStdlibType 
ToolChain::GetCXXStdlibType(const ArgList &Args) const{
 cxxStdlibType = ToolChain::CST_Libcxx;
   else if (LibName == "libstdc++")
 cxxStdlibType = ToolChain::CST_Libstdcxx;
+  else if (LibName == "stl")
+cxxStdlibType = ToolChain::CST_Stl;
   else if (LibName == "platform")
 cxxStdlibType = GetDefaultCXXStdlibType();
   else {
@@ -1290,6 +1296,9 @@ void ToolChain::AddCXXStdlibLibArgs(const ArgList &Args,
   case ToolChain::CST_Libstdcxx:
 CmdArgs.push_back("-lstdc++");
 break;
+
+  default:
+break;
   }
 }
 
diff --git a/clang/lib/Driver/ToolChains/MSVC.cpp 
b/clang/lib/Driver/ToolChains/MSVC.cpp
index ca266e3e1d1d3..bf1b6d3b9bc84 100644
--- a/clang/lib/Driver/ToolChains/MSVC.cpp
+++ b/clang/lib/Driver/ToolChains/MSVC.cpp
@@ -31,12 +31,12 @@
 #include 
 
 #ifdef _WIN32
-  #define WIN32_LEAN_AND_MEAN
-  #define NOGDI
-  #ifndef NOMINMAX
-#define NOMINMAX
-  #endif
-  #include 
+#define WIN32_LEAN_AND_MEAN
+#define NOGDI
+#ifndef NOMINMAX
+#define NOMINMAX
+#endif
+#include 
 #endif
 
 using namespace clang::driver;
@@ -95,43 +95,52 @@ void visualstudio::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   // the environment variable is set however, assume the user knows what
   // they're doing. If the user passes /vctoolsdir or /winsdkdir, trust that
   // over env vars.
-  if (const Arg *A = Args.getLastArg(options::OPT__SLASH_diasdkdir,
- options::OPT__SLASH_winsysroot)) {
-// cl.exe doesn't find the DIA SDK automatically, so this too requires
-// explicit flags and doesn't automatically look in "DIA SDK" relative
-// to the path we found for VCToolChainPath.
-llvm::SmallString<128> DIAPath(A->getValue());
-if (A->getOption().getID() == options::OPT__SLASH_winsysroot)
-  llvm::sys::path::append(DIAPath, "DIA SDK");
-
-// The DIA SDK always uses the legacy vc

[clang] [llvm] [BPF] Fix linking issues in static map initializers (PR #91310)

2024-06-30 Thread Nick Zavaritsky via cfe-commits

mejedi wrote:

@yonghong-song @efriedma-quic Any chance we could get it merged?

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


[clang] [llvm] [PAC][Driver] Implement `-mbranch-protection=pauthabi` option (PR #97237)

2024-06-30 Thread Daniil Kovalev via cfe-commits

https://github.com/kovdan01 created 
https://github.com/llvm/llvm-project/pull/97237

Enable the following ptrauth flags when `pauthabi` is passed as branch 
protection:

- `intrinsics`;
- `calls`;
- `returns`;
- `auth-traps`;
- `vtable-pointer-address-discrimination`;
- `vtable-pointer-type-discrimination`;
- `init-fini`.

Co-authored-by: Anatoly Trosinenko 

>From 3b4b1b1739b810d758e68f30c48b648963cff740 Mon Sep 17 00:00:00 2001
From: Daniil Kovalev 
Date: Mon, 1 Jul 2024 00:50:21 +0300
Subject: [PATCH] [PAC][Driver] Implement `-mbranch-protection=pauthabi` option

Enable the following ptrauth flags when `pauthabi` is passed as branch
protection:

- `intrinsics`;
- `calls`;
- `returns`;
- `auth-traps`;
- `vtable-pointer-address-discrimination`;
- `vtable-pointer-type-discrimination`;
- `init-fini`.

Co-authored-by: Anatoly Trosinenko 
---
 clang/lib/Driver/ToolChains/Clang.cpp | 38 +++
 clang/test/Driver/aarch64-ptrauth.c   | 36 ++
 .../llvm/TargetParser/ARMTargetParserCommon.h |  1 +
 .../TargetParser/ARMTargetParserCommon.cpp|  6 ++-
 4 files changed, 72 insertions(+), 9 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 1b7cc82ea816e..4ed1ece22b7aa 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -1484,6 +1484,39 @@ void AddUnalignedAccessWarning(ArgStringList &CmdArgs) {
 }
 }
 
+static void handlePAuthABIOption(const ArgList &DriverArgs,
+ ArgStringList &CC1Args, const Driver &D) {
+  if (!DriverArgs.hasArg(options::OPT_fptrauth_intrinsics,
+ options::OPT_fno_ptrauth_intrinsics))
+CC1Args.push_back("-fptrauth-intrinsics");
+
+  if (!DriverArgs.hasArg(options::OPT_fptrauth_calls,
+ options::OPT_fno_ptrauth_calls))
+CC1Args.push_back("-fptrauth-calls");
+
+  if (!DriverArgs.hasArg(options::OPT_fptrauth_returns,
+ options::OPT_fno_ptrauth_returns))
+CC1Args.push_back("-fptrauth-returns");
+
+  if (!DriverArgs.hasArg(options::OPT_fptrauth_auth_traps,
+ options::OPT_fno_ptrauth_auth_traps))
+CC1Args.push_back("-fptrauth-auth-traps");
+
+  if (!DriverArgs.hasArg(
+  options::OPT_fptrauth_vtable_pointer_address_discrimination,
+  options::OPT_fno_ptrauth_vtable_pointer_address_discrimination))
+CC1Args.push_back("-fptrauth-vtable-pointer-address-discrimination");
+
+  if (!DriverArgs.hasArg(
+  options::OPT_fptrauth_vtable_pointer_type_discrimination,
+  options::OPT_fno_ptrauth_vtable_pointer_type_discrimination))
+CC1Args.push_back("-fptrauth-vtable-pointer-type-discrimination");
+
+  if (!DriverArgs.hasArg(options::OPT_fptrauth_init_fini,
+ options::OPT_fno_ptrauth_init_fini))
+CC1Args.push_back("-fptrauth-init-fini");
+}
+
 static void CollectARMPACBTIOptions(const ToolChain &TC, const ArgList &Args,
 ArgStringList &CmdArgs, bool isAArch64) {
   const Arg *A = isAArch64
@@ -1537,11 +1570,16 @@ static void CollectARMPACBTIOptions(const ToolChain 
&TC, const ArgList &Args,
 if (!isAArch64 && PBP.Key == "b_key")
   D.Diag(diag::warn_unsupported_branch_protection)
   << "b-key" << A->getAsString(Args);
+if (!isAArch64 && PBP.HasPauthABI)
+  D.Diag(diag::warn_unsupported_branch_protection)
+  << "pauthabi" << A->getAsString(Args);
 Scope = PBP.Scope;
 Key = PBP.Key;
 BranchProtectionPAuthLR = PBP.BranchProtectionPAuthLR;
 IndirectBranches = PBP.BranchTargetEnforcement;
 GuardedControlStack = PBP.GuardedControlStack;
+if (isAArch64 && PBP.HasPauthABI)
+  handlePAuthABIOption(Args, CmdArgs, D);
   }
 
   CmdArgs.push_back(
diff --git a/clang/test/Driver/aarch64-ptrauth.c 
b/clang/test/Driver/aarch64-ptrauth.c
index fa0125f4b22a9..dc63545a47a86 100644
--- a/clang/test/Driver/aarch64-ptrauth.c
+++ b/clang/test/Driver/aarch64-ptrauth.c
@@ -13,13 +13,33 @@
 // RUN:   %s 2>&1 | FileCheck %s --check-prefix=ALL
 // ALL: "-cc1"{{.*}} "-fptrauth-intrinsics" "-fptrauth-calls" 
"-fptrauth-returns" "-fptrauth-auth-traps" 
"-fptrauth-vtable-pointer-address-discrimination" 
"-fptrauth-vtable-pointer-type-discrimination" "-fptrauth-init-fini"
 
+// RUN: %clang -### -c --target=aarch64 -mbranch-protection=pauthabi %s 2>&1 | 
\
+// RUN:   FileCheck %s --check-prefix=PAUTHABI1
+// PAUTHABI1: "-cc1"{{.*}} "-fptrauth-intrinsics" "-fptrauth-calls" 
"-fptrauth-returns" "-fptrauth-auth-traps" 
"-fptrauth-vtable-pointer-address-discrimination" 
"-fptrauth-vtable-pointer-type-discrimination" "-fptrauth-init-fini"
+
+// RUN: %clang -### -c --target=aarch64 -mbranch-protection=pauthabi 
-fno-ptrauth-intrinsics \
+// RUN:   -fno-ptrauth-calls -fno-ptrauth-returns -fno-ptrauth-auth-traps \
+// RUN:   -fno-ptrauth-vtable-pointer-address-discrimination 
-fno-ptrauth-vtable-poin

[clang] [llvm] [PAC][Driver] Implement `-mbranch-protection=pauthabi` option (PR #97237)

2024-06-30 Thread Daniil Kovalev via cfe-commits

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


[clang] [llvm] [Hashing] Use a non-deterministic seed if LLVM_ENABLE_ABI_BREAKING_CHECKS (PR #96282)

2024-06-30 Thread Mehdi Amini via cfe-commits

joker-eph wrote:

The premerge config seems broken because of this PR.

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


[clang] [llvm] [Hashing] Use a non-deterministic seed if LLVM_ENABLE_ABI_BREAKING_CHECKS (PR #96282)

2024-06-30 Thread Mehdi Amini via cfe-commits


@@ -322,24 +306,20 @@ struct hash_state {
   }
 };
 
-
-/// A global, fixed seed-override variable.
-///
-/// This variable can be set using the \see llvm::set_fixed_execution_seed
-/// function. See that function for details. Do not, under any circumstances,
-/// set or read this variable.
-extern uint64_t fixed_seed_override;
-
+/// In LLVM_ENABLE_ABI_BREAKING_CHECKS builds, the seed is non-deterministic
+/// (address of a variable) to prevent having users depend on the particular
+/// hash values. On platforms without ASLR, this is still likely
+/// non-deterministic per build.
 inline uint64_t get_execution_seed() {
-  // FIXME: This needs to be a per-execution seed. This is just a placeholder
-  // implementation. Switching to a per-execution seed is likely to flush out
-  // instability bugs and so will happen as its own commit.
-  //
-  // However, if there is a fixed seed override set the first time this is
-  // called, return that instead of the per-execution seed.
-  const uint64_t seed_prime = 0xff51afd7ed558ccdULL;
-  static uint64_t seed = fixed_seed_override ? fixed_seed_override : 
seed_prime;
-  return seed;
+  // Work around x86-64 negative offset folding for old Clang -fno-pic
+  // https://reviews.llvm.org/D93931
+#if LLVM_ENABLE_ABI_BREAKING_CHECKS && 
\
+(!defined(__clang__) || __clang_major__ > 11)

joker-eph wrote:

Wouldn't this affect any access to a DenseMap across the boundary for example?

That is any API where LLVM would initialize a DenseMap and return a reference 
to it to the user which then access elements by computing key hashes?

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


[clang] [clang][ThreadSafety] Check trylock function success and return types (PR #95290)

2024-06-30 Thread Aaron Puchert via cfe-commits

aaronpuchert wrote:

Thanks for looping me in and sorry for the late reply!

> However, I'm not certain we implement the analysis in an exception-aware way.

If I remember correctly, the CFG is still without exception-handling edges by 
default, and support for those edges is still rudimentary and breaks other 
warnings that operate on the same CFG. It would definitely be nice, but it 
might be a bigger project.

> I was really surprised to see a trylock method that returns a pointer! 
> Confusingly, the "success" parameter to the attribute is `1`. I think the 
> semantics work out so that returning a non-`nullptr` value indicates 
> successful mutex acquisition.

We use something like this in our code base, though I believe we've written it 
as `true`. Basically, the function returns some kind of handle/ticket that 
needs to be passed into the unlock method.

> Maybe we should be lenient and only enforce that the return type is boolean, 
> integer, or pointer?

We can probably generalize this a bit. I think we should be checking for 
[contextually convertibility to 
`bool`](https://eel.is/c++draft/conv.general#def:conversion,contextual_to_bool).
 This would cover `bool`, pointers, smart pointers, and other custom types with 
an `explicit operator bool()`. Support for arbitrary integers/enumerations 
would also be nice, but it's a bit harder to track the data flow for them. We 
can probably only support them unchanged, whereas for booleans we currently 
allow negations and some comparisons. Didn't check how well this is supported.

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


[libc] [libunwind] [WIP] Enough to get `libc` to build `clang` on `aarch64` (PR #97231)

2024-06-30 Thread Izaak Schroeder via cfe-commits

https://github.com/izaakschroeder updated 
https://github.com/llvm/llvm-project/pull/97231

>From 31dc769c1866a4a0100dde0a3743c215a9a5f5eb Mon Sep 17 00:00:00 2001
From: Izaak Schroeder 
Date: Sun, 30 Jun 2024 13:33:16 -0700
Subject: [PATCH 1/5] [libc]: add missing aarch64 headers

---
 libc/config/linux/aarch64/entrypoints.txt | 3 +++
 libc/config/linux/aarch64/headers.txt | 6 ++
 2 files changed, 9 insertions(+)

diff --git a/libc/config/linux/aarch64/entrypoints.txt 
b/libc/config/linux/aarch64/entrypoints.txt
index 8a26536cea9a0..b59400db81fed 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -308,6 +308,9 @@ set(TARGET_LIBC_ENTRYPOINTS
 libc.src.unistd.unlink
 libc.src.unistd.unlinkat
 libc.src.unistd.write
+
+# XXX
+libc.src.assert.__assert_fail
 )
 
 set(TARGET_LIBM_ENTRYPOINTS
diff --git a/libc/config/linux/aarch64/headers.txt 
b/libc/config/linux/aarch64/headers.txt
index 7d25877cefcc8..ed126d6128871 100644
--- a/libc/config/linux/aarch64/headers.txt
+++ b/libc/config/linux/aarch64/headers.txt
@@ -31,4 +31,10 @@ set(TARGET_PUBLIC_HEADERS
 libc.include.sys_ioctl
 # Disabled due to epoll_wait syscalls not being available on this platform.
 # libc.include.sys_epoll
+
+# XXX
+libc.include.sys_auxv
+libc.include.fcntl
+libc.include.sched
+libc.include.sys_stat
 )

>From a5f8ee220c088a39d9b4bf60986166e83ffafffa Mon Sep 17 00:00:00 2001
From: Izaak Schroeder 
Date: Sun, 30 Jun 2024 13:33:38 -0700
Subject: [PATCH 2/5] [libunwind]: remove needless `sys/uio.h`

No reference to `readv` or `writev`.
---
 libunwind/src/UnwindCursor.hpp | 1 -
 1 file changed, 1 deletion(-)

diff --git a/libunwind/src/UnwindCursor.hpp b/libunwind/src/UnwindCursor.hpp
index 66fe8e2a32cca..677e842d8a22b 100644
--- a/libunwind/src/UnwindCursor.hpp
+++ b/libunwind/src/UnwindCursor.hpp
@@ -36,7 +36,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #define _LIBUNWIND_CHECK_LINUX_SIGRETURN 1
 #endif

>From 1083aecfe1be3c1cf427d4ffd2b4fad3d5129d4c Mon Sep 17 00:00:00 2001
From: Izaak Schroeder 
Date: Sun, 30 Jun 2024 13:44:52 -0700
Subject: [PATCH 3/5] [libc]: function spec for `getauxval`

---
 libc/spec/gnu_ext.td | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/libc/spec/gnu_ext.td b/libc/spec/gnu_ext.td
index 161bb4e4a0d9d..e360c766c5c54 100644
--- a/libc/spec/gnu_ext.td
+++ b/libc/spec/gnu_ext.td
@@ -237,7 +237,11 @@ def GnuExtensions : StandardSpec<"GNUExtensions"> {
   [], // Types
   [], // Enumerations
   [
-//TODO: Add getauxval here
+  FunctionSpec<
+  "getauxval",
+  RetValSpec,
+  [ArgSpec]
+  >,
   ]  // Functions
   >;
 

>From e9628ce037c225c3769cec2589745f7978e7edc4 Mon Sep 17 00:00:00 2001
From: Izaak Schroeder 
Date: Sun, 30 Jun 2024 14:06:19 -0700
Subject: [PATCH 4/5] [libc]: hack `ExitCallbackList` always public

---
 libc/src/stdlib/exit_handler.h | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/libc/src/stdlib/exit_handler.h b/libc/src/stdlib/exit_handler.h
index 8494c2f2e526e..db731a46f44c9 100644
--- a/libc/src/stdlib/exit_handler.h
+++ b/libc/src/stdlib/exit_handler.h
@@ -31,10 +31,8 @@ struct AtExitUnit {
 
 #if defined(LIBC_TARGET_ARCH_IS_GPU)
 using ExitCallbackList = FixedVector;
-#elif defined(LIBC_COPT_PUBLIC_PACKAGING)
-using ExitCallbackList = ReverseOrderBlockStore;
 #else
-using ExitCallbackList = FixedVector;
+using ExitCallbackList = ReverseOrderBlockStore;
 #endif
 
 extern ExitCallbackList atexit_callbacks;

>From e3ed9aac99ede8be5d6d228f43c652423206e67c Mon Sep 17 00:00:00 2001
From: Izaak Schroeder 
Date: Sun, 30 Jun 2024 14:15:21 -0700
Subject: [PATCH 5/5] [libc]: add `Scrt1.o`

---
 libc/startup/linux/CMakeLists.txt | 11 ++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/libc/startup/linux/CMakeLists.txt 
b/libc/startup/linux/CMakeLists.txt
index 336c5d0f6bfa2..b721d15091227 100644
--- a/libc/startup/linux/CMakeLists.txt
+++ b/libc/startup/linux/CMakeLists.txt
@@ -118,6 +118,15 @@ merge_relocatable_object(
   .do_start
 )
 
+# HACK: Is this even ok?
+# For reference: `Scrt1` is used when `-fpie` vs `crt1` for `-fno-pie`
+merge_relocatable_object(
+  Scrt1
+  .${LIBC_TARGET_ARCHITECTURE}.start
+  .${LIBC_TARGET_ARCHITECTURE}.tls
+  .do_start
+)
+
 add_startup_object(
   crti
   SRC
@@ -131,7 +140,7 @@ add_startup_object(
 )
 
 add_custom_target(libc-startup)
-set(startup_components crt1 crti crtn)
+set(startup_components Scrt1 crt1 crti crtn)
 foreach(target IN LISTS startup_components)
   set(fq_target_name libc.startup.linux.${target})
   add_dependencies(libc-startup ${fq_target_name})

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


[clang] [clang][ThreadSafety] Check trylock function success and return types (PR #95290)

2024-06-30 Thread Aaron Puchert via cfe-commits


@@ -756,7 +771,68 @@ void etf_fun_params(int lvar 
EXCLUSIVE_TRYLOCK_FUNCTION(1)); // \
 
 // Check argument parsing.
 
-// legal attribute arguments
+int global_int = 0;
+int* etf_fun_with_global_ptr_success() EXCLUSIVE_TRYLOCK_FUNCTION(&global_int, 
&mu1); //\
+  // expected-error {{'exclusive_trylock_function' attribute requires 
parameter 1 to be nullptr or a bool, int, or enum literal}}
+
+#ifdef CPP11
+constexpr int kTrylockSuccess = 1;
+int etf_succ_constexpr() EXCLUSIVE_TRYLOCK_FUNCTION(kTrylockSuccess, mu2); // \
+  // expected-error {{'exclusive_trylock_function' attribute requires 
parameter 1 to be nullptr or a bool, int, or enum literal}}
+
+int success_value_non_constant = 1;
+
+bool etf_succ_variable() 
EXCLUSIVE_TRYLOCK_FUNCTION(success_value_non_constant, mu2); //\
+  // expected-error {{attribute requires parameter 1 to be nullptr or a bool, 
int, or enum literal}}
+#endif
+
+
+// Legal permutations of the first argument and function return type.
+struct TrylockResult;
+
+#ifdef CPP11
+int* etf_fun_with_nullptr_success() EXCLUSIVE_TRYLOCK_FUNCTION(nullptr, &mu1);
+#endif
+
+#ifndef __cplusplus
+int* etf_fun_with_nullptr_success() EXCLUSIVE_TRYLOCK_FUNCTION(NULL, &mu1);
+#endif
+
+int etf_succ_1_ret_i() EXCLUSIVE_TRYLOCK_FUNCTION(1, mu2);
+bool etf_succ_1_ret_b() EXCLUSIVE_TRYLOCK_FUNCTION(1, mu2);
+TrylockResult *etf_succ_1_ret_p() EXCLUSIVE_TRYLOCK_FUNCTION(1, mu2);
+
+int etf_succ_true_ret_i() EXCLUSIVE_TRYLOCK_FUNCTION(true, mu2);
+bool etf_succ_true_ret_b() EXCLUSIVE_TRYLOCK_FUNCTION(true, mu2);
+TrylockResult *etf_succ_true_ret_p() EXCLUSIVE_TRYLOCK_FUNCTION(true, mu2);
+
+int etf_succ_false_ret_i() EXCLUSIVE_TRYLOCK_FUNCTION(false, mu2);
+bool etf_succ_false_ret_b() EXCLUSIVE_TRYLOCK_FUNCTION(false, mu2);
+TrylockResult *etf_succ_false_ret_p() EXCLUSIVE_TRYLOCK_FUNCTION(false, mu2);
+
+enum TrylockSuccessEnum { TrylockNotAcquired = 0, TrylockAcquired };
+int etf_succ_enum_ret_i() EXCLUSIVE_TRYLOCK_FUNCTION(TrylockAcquired, mu2);
+bool etf_succ_enum_ret_b() EXCLUSIVE_TRYLOCK_FUNCTION(TrylockAcquired, mu2);
+TrylockResult *etf_succ_enum_ret_p()
+EXCLUSIVE_TRYLOCK_FUNCTION(TrylockAcquired, mu2);
+
+#ifdef CPP11
+enum class TrylockSuccessEnumClass { NotAcquired = 0, Acquired};
+int etf_succ_enum_class_ret_i()
+EXCLUSIVE_TRYLOCK_FUNCTION(TrylockSuccessEnumClass::Acquired, mu2);
+bool etf_succ_enum_class_ret_b()
+EXCLUSIVE_TRYLOCK_FUNCTION(TrylockSuccessEnumClass::Acquired, mu2);
+TrylockResult *etf_succ_enum_class_ret_p()
+EXCLUSIVE_TRYLOCK_FUNCTION(TrylockSuccessEnumClass::Acquired, mu2);
+#endif

aaronpuchert wrote:

I think `enum class` should not be allowed for now, because we can't convert it 
to `bool`.

Should we add proper support for enumerations, we should probably not convert 
them to `bool` but rather check for equality.

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


  1   2   >