[clang] [clang] Fix parenthesized list initialization of arrays not working with `new` (PR #76976)

2024-01-04 Thread Alan Zhao via cfe-commits

https://github.com/alanzhao1 created 
https://github.com/llvm/llvm-project/pull/76976

This bug is caused by parenthesized list initialization not being implemented 
in `CodeGenFunction::EmitNewArrayInitializer(...)`.

Parenthesized list initialization of `struct`s  with `operator new` already 
works in Clang and is not affected by this bug.

Additionally, fix the test new-delete.cpp as it incorrectly assumes that using 
parentheses with operator new to initialize arrays is illegal for C++ versions 
>= C++17.

Fixes #68198

>From ee4e3c8634bb876166ee753a4ebcbf3c1699a175 Mon Sep 17 00:00:00 2001
From: Alan Zhao 
Date: Wed, 3 Jan 2024 12:29:21 -0800
Subject: [PATCH] [clang] Fix parenthesized list initialization of arrays not
 working with `new`

This bug is caused by parenthesized list initialization not being
implemented in `CodeGenFunction::EmitNewArrayInitializer(...)`.

Parenthesized list initialization of `struct`s  with `operator new`
already works in Clang and is not affected by this bug.

Additionally, fix the test new-delete.cpp as it incorrectly assumes that
using parentheses with operator new to initialize arrays is illegal for
C++ versions >= C++17.

Fixes #68198
---
 clang/docs/ReleaseNotes.rst|  3 +
 clang/lib/CodeGen/CGExprCXX.cpp| 17 ++---
 clang/lib/Sema/SemaExprCXX.cpp |  6 +-
 clang/test/CodeGen/paren-list-agg-init.cpp | 72 ++
 clang/test/SemaCXX/new-delete.cpp  | 20 +++---
 5 files changed, 98 insertions(+), 20 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c7bf162426a68c..211fd62a1ee85f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -844,6 +844,9 @@ Bug Fixes to C++ Support
 - Fix crash when parsing nested requirement. Fixes:
   (`#73112 `_)
 
+- Clang now allows parenthesized initialization of arrays in `operator new[]`.
+  Fixes: (`#68198 `_)
+
 Bug Fixes to AST Handling
 ^
 - Fixed an import failure of recursive friend class template.
diff --git a/clang/lib/CodeGen/CGExprCXX.cpp b/clang/lib/CodeGen/CGExprCXX.cpp
index 98ae56e2df8818..72c61bfb5ec344 100644
--- a/clang/lib/CodeGen/CGExprCXX.cpp
+++ b/clang/lib/CodeGen/CGExprCXX.cpp
@@ -1038,11 +1038,13 @@ void CodeGenFunction::EmitNewArrayInitializer(
 return true;
   };
 
+  const InitListExpr *ILE = dyn_cast(Init);
+  const CXXParenListInitExpr *CPLIE = dyn_cast(Init);
   // If the initializer is an initializer list, first do the explicit elements.
-  if (const InitListExpr *ILE = dyn_cast(Init)) {
+  if (ILE || CPLIE) {
 // Initializing from a (braced) string literal is a special case; the init
 // list element does not initialize a (single) array element.
-if (ILE->isStringLiteralInit()) {
+if (ILE && ILE->isStringLiteralInit()) {
   // Initialize the initial portion of length equal to that of the string
   // literal. The allocation must be for at least this much; we emitted a
   // check for that earlier.
@@ -1073,7 +1075,7 @@ void CodeGenFunction::EmitNewArrayInitializer(
   return;
 }
 
-InitListElements = ILE->getNumInits();
+InitListElements = ILE ? ILE->getNumInits() : CPLIE->getInitExprs().size();
 
 // If this is a multi-dimensional array new, we will initialize multiple
 // elements with each init list element.
@@ -1101,7 +1103,8 @@ void CodeGenFunction::EmitNewArrayInitializer(
 }
 
 CharUnits StartAlign = CurPtr.getAlignment();
-for (unsigned i = 0, e = ILE->getNumInits(); i != e; ++i) {
+ArrayRef InitExprs = ILE ? ILE->inits() : CPLIE->getInitExprs();
+for (unsigned i = 0; i < InitExprs.size(); ++i) {
   // Tell the cleanup that it needs to destroy up to this
   // element.  TODO: some of these stores can be trivially
   // observed to be unnecessary.
@@ -,8 +1114,8 @@ void CodeGenFunction::EmitNewArrayInitializer(
   // FIXME: If the last initializer is an incomplete initializer list for
   // an array, and we have an array filler, we can fold together the two
   // initialization loops.
-  StoreAnyExprIntoOneUnit(*this, ILE->getInit(i),
-  ILE->getInit(i)->getType(), CurPtr,
+  Expr *IE = InitExprs[i];
+  StoreAnyExprIntoOneUnit(*this, IE, IE->getType(), CurPtr,
   AggValueSlot::DoesNotOverlap);
   CurPtr = Address(Builder.CreateInBoundsGEP(
CurPtr.getElementType(), CurPtr.getPointer(),
@@ -1122,7 +1125,7 @@ void CodeGenFunction::EmitNewArrayInitializer(
 }
 
 // The remaining elements are filled with the array filler expression.
-Init = ILE->getArrayFiller();
+Init = ILE ? ILE->getArrayFiller() : CPLIE->getArrayFiller();
 
 // Extract the initializer for the individual array elements by pulling
 // out the array filler from all 

[clang] [clang] Fix parenthesized list initialization of arrays not working with `new` (PR #76976)

2024-01-04 Thread Alan Zhao via cfe-commits

https://github.com/alanzhao1 updated 
https://github.com/llvm/llvm-project/pull/76976

>From ee4e3c8634bb876166ee753a4ebcbf3c1699a175 Mon Sep 17 00:00:00 2001
From: Alan Zhao 
Date: Wed, 3 Jan 2024 12:29:21 -0800
Subject: [PATCH 1/2] [clang] Fix parenthesized list initialization of arrays
 not working with `new`

This bug is caused by parenthesized list initialization not being
implemented in `CodeGenFunction::EmitNewArrayInitializer(...)`.

Parenthesized list initialization of `struct`s  with `operator new`
already works in Clang and is not affected by this bug.

Additionally, fix the test new-delete.cpp as it incorrectly assumes that
using parentheses with operator new to initialize arrays is illegal for
C++ versions >= C++17.

Fixes #68198
---
 clang/docs/ReleaseNotes.rst|  3 +
 clang/lib/CodeGen/CGExprCXX.cpp| 17 ++---
 clang/lib/Sema/SemaExprCXX.cpp |  6 +-
 clang/test/CodeGen/paren-list-agg-init.cpp | 72 ++
 clang/test/SemaCXX/new-delete.cpp  | 20 +++---
 5 files changed, 98 insertions(+), 20 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c7bf162426a68c..211fd62a1ee85f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -844,6 +844,9 @@ Bug Fixes to C++ Support
 - Fix crash when parsing nested requirement. Fixes:
   (`#73112 `_)
 
+- Clang now allows parenthesized initialization of arrays in `operator new[]`.
+  Fixes: (`#68198 `_)
+
 Bug Fixes to AST Handling
 ^
 - Fixed an import failure of recursive friend class template.
diff --git a/clang/lib/CodeGen/CGExprCXX.cpp b/clang/lib/CodeGen/CGExprCXX.cpp
index 98ae56e2df8818..72c61bfb5ec344 100644
--- a/clang/lib/CodeGen/CGExprCXX.cpp
+++ b/clang/lib/CodeGen/CGExprCXX.cpp
@@ -1038,11 +1038,13 @@ void CodeGenFunction::EmitNewArrayInitializer(
 return true;
   };
 
+  const InitListExpr *ILE = dyn_cast(Init);
+  const CXXParenListInitExpr *CPLIE = dyn_cast(Init);
   // If the initializer is an initializer list, first do the explicit elements.
-  if (const InitListExpr *ILE = dyn_cast(Init)) {
+  if (ILE || CPLIE) {
 // Initializing from a (braced) string literal is a special case; the init
 // list element does not initialize a (single) array element.
-if (ILE->isStringLiteralInit()) {
+if (ILE && ILE->isStringLiteralInit()) {
   // Initialize the initial portion of length equal to that of the string
   // literal. The allocation must be for at least this much; we emitted a
   // check for that earlier.
@@ -1073,7 +1075,7 @@ void CodeGenFunction::EmitNewArrayInitializer(
   return;
 }
 
-InitListElements = ILE->getNumInits();
+InitListElements = ILE ? ILE->getNumInits() : CPLIE->getInitExprs().size();
 
 // If this is a multi-dimensional array new, we will initialize multiple
 // elements with each init list element.
@@ -1101,7 +1103,8 @@ void CodeGenFunction::EmitNewArrayInitializer(
 }
 
 CharUnits StartAlign = CurPtr.getAlignment();
-for (unsigned i = 0, e = ILE->getNumInits(); i != e; ++i) {
+ArrayRef InitExprs = ILE ? ILE->inits() : CPLIE->getInitExprs();
+for (unsigned i = 0; i < InitExprs.size(); ++i) {
   // Tell the cleanup that it needs to destroy up to this
   // element.  TODO: some of these stores can be trivially
   // observed to be unnecessary.
@@ -,8 +1114,8 @@ void CodeGenFunction::EmitNewArrayInitializer(
   // FIXME: If the last initializer is an incomplete initializer list for
   // an array, and we have an array filler, we can fold together the two
   // initialization loops.
-  StoreAnyExprIntoOneUnit(*this, ILE->getInit(i),
-  ILE->getInit(i)->getType(), CurPtr,
+  Expr *IE = InitExprs[i];
+  StoreAnyExprIntoOneUnit(*this, IE, IE->getType(), CurPtr,
   AggValueSlot::DoesNotOverlap);
   CurPtr = Address(Builder.CreateInBoundsGEP(
CurPtr.getElementType(), CurPtr.getPointer(),
@@ -1122,7 +1125,7 @@ void CodeGenFunction::EmitNewArrayInitializer(
 }
 
 // The remaining elements are filled with the array filler expression.
-Init = ILE->getArrayFiller();
+Init = ILE ? ILE->getArrayFiller() : CPLIE->getArrayFiller();
 
 // Extract the initializer for the individual array elements by pulling
 // out the array filler from all the nested initializer lists. This avoids
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 4ae04358d5df7c..71e420648ce7af 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -1947,11 +1947,11 @@ Sema::ActOnCXXNew(SourceLocation StartLoc, bool 
UseGlobal,
 }
 
 static bool isLegalArrayNewInitializer(CXXNewInitializationStyle Style,
-   

[clang] [clang] Fix parenthesized list initialization of arrays not working with `new` (PR #76976)

2024-01-04 Thread Alan Zhao via cfe-commits

https://github.com/alanzhao1 updated 
https://github.com/llvm/llvm-project/pull/76976

>From ee4e3c8634bb876166ee753a4ebcbf3c1699a175 Mon Sep 17 00:00:00 2001
From: Alan Zhao 
Date: Wed, 3 Jan 2024 12:29:21 -0800
Subject: [PATCH 1/3] [clang] Fix parenthesized list initialization of arrays
 not working with `new`

This bug is caused by parenthesized list initialization not being
implemented in `CodeGenFunction::EmitNewArrayInitializer(...)`.

Parenthesized list initialization of `struct`s  with `operator new`
already works in Clang and is not affected by this bug.

Additionally, fix the test new-delete.cpp as it incorrectly assumes that
using parentheses with operator new to initialize arrays is illegal for
C++ versions >= C++17.

Fixes #68198
---
 clang/docs/ReleaseNotes.rst|  3 +
 clang/lib/CodeGen/CGExprCXX.cpp| 17 ++---
 clang/lib/Sema/SemaExprCXX.cpp |  6 +-
 clang/test/CodeGen/paren-list-agg-init.cpp | 72 ++
 clang/test/SemaCXX/new-delete.cpp  | 20 +++---
 5 files changed, 98 insertions(+), 20 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c7bf162426a68c..211fd62a1ee85f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -844,6 +844,9 @@ Bug Fixes to C++ Support
 - Fix crash when parsing nested requirement. Fixes:
   (`#73112 `_)
 
+- Clang now allows parenthesized initialization of arrays in `operator new[]`.
+  Fixes: (`#68198 `_)
+
 Bug Fixes to AST Handling
 ^
 - Fixed an import failure of recursive friend class template.
diff --git a/clang/lib/CodeGen/CGExprCXX.cpp b/clang/lib/CodeGen/CGExprCXX.cpp
index 98ae56e2df8818..72c61bfb5ec344 100644
--- a/clang/lib/CodeGen/CGExprCXX.cpp
+++ b/clang/lib/CodeGen/CGExprCXX.cpp
@@ -1038,11 +1038,13 @@ void CodeGenFunction::EmitNewArrayInitializer(
 return true;
   };
 
+  const InitListExpr *ILE = dyn_cast(Init);
+  const CXXParenListInitExpr *CPLIE = dyn_cast(Init);
   // If the initializer is an initializer list, first do the explicit elements.
-  if (const InitListExpr *ILE = dyn_cast(Init)) {
+  if (ILE || CPLIE) {
 // Initializing from a (braced) string literal is a special case; the init
 // list element does not initialize a (single) array element.
-if (ILE->isStringLiteralInit()) {
+if (ILE && ILE->isStringLiteralInit()) {
   // Initialize the initial portion of length equal to that of the string
   // literal. The allocation must be for at least this much; we emitted a
   // check for that earlier.
@@ -1073,7 +1075,7 @@ void CodeGenFunction::EmitNewArrayInitializer(
   return;
 }
 
-InitListElements = ILE->getNumInits();
+InitListElements = ILE ? ILE->getNumInits() : CPLIE->getInitExprs().size();
 
 // If this is a multi-dimensional array new, we will initialize multiple
 // elements with each init list element.
@@ -1101,7 +1103,8 @@ void CodeGenFunction::EmitNewArrayInitializer(
 }
 
 CharUnits StartAlign = CurPtr.getAlignment();
-for (unsigned i = 0, e = ILE->getNumInits(); i != e; ++i) {
+ArrayRef InitExprs = ILE ? ILE->inits() : CPLIE->getInitExprs();
+for (unsigned i = 0; i < InitExprs.size(); ++i) {
   // Tell the cleanup that it needs to destroy up to this
   // element.  TODO: some of these stores can be trivially
   // observed to be unnecessary.
@@ -,8 +1114,8 @@ void CodeGenFunction::EmitNewArrayInitializer(
   // FIXME: If the last initializer is an incomplete initializer list for
   // an array, and we have an array filler, we can fold together the two
   // initialization loops.
-  StoreAnyExprIntoOneUnit(*this, ILE->getInit(i),
-  ILE->getInit(i)->getType(), CurPtr,
+  Expr *IE = InitExprs[i];
+  StoreAnyExprIntoOneUnit(*this, IE, IE->getType(), CurPtr,
   AggValueSlot::DoesNotOverlap);
   CurPtr = Address(Builder.CreateInBoundsGEP(
CurPtr.getElementType(), CurPtr.getPointer(),
@@ -1122,7 +1125,7 @@ void CodeGenFunction::EmitNewArrayInitializer(
 }
 
 // The remaining elements are filled with the array filler expression.
-Init = ILE->getArrayFiller();
+Init = ILE ? ILE->getArrayFiller() : CPLIE->getArrayFiller();
 
 // Extract the initializer for the individual array elements by pulling
 // out the array filler from all the nested initializer lists. This avoids
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 4ae04358d5df7c..71e420648ce7af 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -1947,11 +1947,11 @@ Sema::ActOnCXXNew(SourceLocation StartLoc, bool 
UseGlobal,
 }
 
 static bool isLegalArrayNewInitializer(CXXNewInitializationStyle Style,
-   

[clang] [clang] Fix parenthesized list initialization of arrays not working with `new` (PR #76976)

2024-01-04 Thread Alan Zhao via cfe-commits

https://github.com/alanzhao1 updated 
https://github.com/llvm/llvm-project/pull/76976

>From ee4e3c8634bb876166ee753a4ebcbf3c1699a175 Mon Sep 17 00:00:00 2001
From: Alan Zhao 
Date: Wed, 3 Jan 2024 12:29:21 -0800
Subject: [PATCH 1/4] [clang] Fix parenthesized list initialization of arrays
 not working with `new`

This bug is caused by parenthesized list initialization not being
implemented in `CodeGenFunction::EmitNewArrayInitializer(...)`.

Parenthesized list initialization of `struct`s  with `operator new`
already works in Clang and is not affected by this bug.

Additionally, fix the test new-delete.cpp as it incorrectly assumes that
using parentheses with operator new to initialize arrays is illegal for
C++ versions >= C++17.

Fixes #68198
---
 clang/docs/ReleaseNotes.rst|  3 +
 clang/lib/CodeGen/CGExprCXX.cpp| 17 ++---
 clang/lib/Sema/SemaExprCXX.cpp |  6 +-
 clang/test/CodeGen/paren-list-agg-init.cpp | 72 ++
 clang/test/SemaCXX/new-delete.cpp  | 20 +++---
 5 files changed, 98 insertions(+), 20 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c7bf162426a68c..211fd62a1ee85f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -844,6 +844,9 @@ Bug Fixes to C++ Support
 - Fix crash when parsing nested requirement. Fixes:
   (`#73112 `_)
 
+- Clang now allows parenthesized initialization of arrays in `operator new[]`.
+  Fixes: (`#68198 `_)
+
 Bug Fixes to AST Handling
 ^
 - Fixed an import failure of recursive friend class template.
diff --git a/clang/lib/CodeGen/CGExprCXX.cpp b/clang/lib/CodeGen/CGExprCXX.cpp
index 98ae56e2df8818..72c61bfb5ec344 100644
--- a/clang/lib/CodeGen/CGExprCXX.cpp
+++ b/clang/lib/CodeGen/CGExprCXX.cpp
@@ -1038,11 +1038,13 @@ void CodeGenFunction::EmitNewArrayInitializer(
 return true;
   };
 
+  const InitListExpr *ILE = dyn_cast(Init);
+  const CXXParenListInitExpr *CPLIE = dyn_cast(Init);
   // If the initializer is an initializer list, first do the explicit elements.
-  if (const InitListExpr *ILE = dyn_cast(Init)) {
+  if (ILE || CPLIE) {
 // Initializing from a (braced) string literal is a special case; the init
 // list element does not initialize a (single) array element.
-if (ILE->isStringLiteralInit()) {
+if (ILE && ILE->isStringLiteralInit()) {
   // Initialize the initial portion of length equal to that of the string
   // literal. The allocation must be for at least this much; we emitted a
   // check for that earlier.
@@ -1073,7 +1075,7 @@ void CodeGenFunction::EmitNewArrayInitializer(
   return;
 }
 
-InitListElements = ILE->getNumInits();
+InitListElements = ILE ? ILE->getNumInits() : CPLIE->getInitExprs().size();
 
 // If this is a multi-dimensional array new, we will initialize multiple
 // elements with each init list element.
@@ -1101,7 +1103,8 @@ void CodeGenFunction::EmitNewArrayInitializer(
 }
 
 CharUnits StartAlign = CurPtr.getAlignment();
-for (unsigned i = 0, e = ILE->getNumInits(); i != e; ++i) {
+ArrayRef InitExprs = ILE ? ILE->inits() : CPLIE->getInitExprs();
+for (unsigned i = 0; i < InitExprs.size(); ++i) {
   // Tell the cleanup that it needs to destroy up to this
   // element.  TODO: some of these stores can be trivially
   // observed to be unnecessary.
@@ -,8 +1114,8 @@ void CodeGenFunction::EmitNewArrayInitializer(
   // FIXME: If the last initializer is an incomplete initializer list for
   // an array, and we have an array filler, we can fold together the two
   // initialization loops.
-  StoreAnyExprIntoOneUnit(*this, ILE->getInit(i),
-  ILE->getInit(i)->getType(), CurPtr,
+  Expr *IE = InitExprs[i];
+  StoreAnyExprIntoOneUnit(*this, IE, IE->getType(), CurPtr,
   AggValueSlot::DoesNotOverlap);
   CurPtr = Address(Builder.CreateInBoundsGEP(
CurPtr.getElementType(), CurPtr.getPointer(),
@@ -1122,7 +1125,7 @@ void CodeGenFunction::EmitNewArrayInitializer(
 }
 
 // The remaining elements are filled with the array filler expression.
-Init = ILE->getArrayFiller();
+Init = ILE ? ILE->getArrayFiller() : CPLIE->getArrayFiller();
 
 // Extract the initializer for the individual array elements by pulling
 // out the array filler from all the nested initializer lists. This avoids
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 4ae04358d5df7c..71e420648ce7af 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -1947,11 +1947,11 @@ Sema::ActOnCXXNew(SourceLocation StartLoc, bool 
UseGlobal,
 }
 
 static bool isLegalArrayNewInitializer(CXXNewInitializationStyle Style,
-   

[clang] [clang] Fix parenthesized list initialization of arrays not working with `new` (PR #76976)

2024-01-05 Thread Alan Zhao via cfe-commits

alanzhao1 wrote:

> Have you considered the following case?
> 
> ```
>   void foo() {
> char* arr = new char[]("asdf");
>   }
> ```

Thanks for catching this - this causes this patch to crash. Working on this 
right now.

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


[clang] [clang] Fix parenthesized list initialization of arrays not working with `new` (PR #76976)

2024-01-09 Thread Alan Zhao via cfe-commits

https://github.com/alanzhao1 updated 
https://github.com/llvm/llvm-project/pull/76976

>From ee4e3c8634bb876166ee753a4ebcbf3c1699a175 Mon Sep 17 00:00:00 2001
From: Alan Zhao 
Date: Wed, 3 Jan 2024 12:29:21 -0800
Subject: [PATCH 1/5] [clang] Fix parenthesized list initialization of arrays
 not working with `new`

This bug is caused by parenthesized list initialization not being
implemented in `CodeGenFunction::EmitNewArrayInitializer(...)`.

Parenthesized list initialization of `struct`s  with `operator new`
already works in Clang and is not affected by this bug.

Additionally, fix the test new-delete.cpp as it incorrectly assumes that
using parentheses with operator new to initialize arrays is illegal for
C++ versions >= C++17.

Fixes #68198
---
 clang/docs/ReleaseNotes.rst|  3 +
 clang/lib/CodeGen/CGExprCXX.cpp| 17 ++---
 clang/lib/Sema/SemaExprCXX.cpp |  6 +-
 clang/test/CodeGen/paren-list-agg-init.cpp | 72 ++
 clang/test/SemaCXX/new-delete.cpp  | 20 +++---
 5 files changed, 98 insertions(+), 20 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c7bf162426a68c..211fd62a1ee85f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -844,6 +844,9 @@ Bug Fixes to C++ Support
 - Fix crash when parsing nested requirement. Fixes:
   (`#73112 `_)
 
+- Clang now allows parenthesized initialization of arrays in `operator new[]`.
+  Fixes: (`#68198 `_)
+
 Bug Fixes to AST Handling
 ^
 - Fixed an import failure of recursive friend class template.
diff --git a/clang/lib/CodeGen/CGExprCXX.cpp b/clang/lib/CodeGen/CGExprCXX.cpp
index 98ae56e2df8818..72c61bfb5ec344 100644
--- a/clang/lib/CodeGen/CGExprCXX.cpp
+++ b/clang/lib/CodeGen/CGExprCXX.cpp
@@ -1038,11 +1038,13 @@ void CodeGenFunction::EmitNewArrayInitializer(
 return true;
   };
 
+  const InitListExpr *ILE = dyn_cast(Init);
+  const CXXParenListInitExpr *CPLIE = dyn_cast(Init);
   // If the initializer is an initializer list, first do the explicit elements.
-  if (const InitListExpr *ILE = dyn_cast(Init)) {
+  if (ILE || CPLIE) {
 // Initializing from a (braced) string literal is a special case; the init
 // list element does not initialize a (single) array element.
-if (ILE->isStringLiteralInit()) {
+if (ILE && ILE->isStringLiteralInit()) {
   // Initialize the initial portion of length equal to that of the string
   // literal. The allocation must be for at least this much; we emitted a
   // check for that earlier.
@@ -1073,7 +1075,7 @@ void CodeGenFunction::EmitNewArrayInitializer(
   return;
 }
 
-InitListElements = ILE->getNumInits();
+InitListElements = ILE ? ILE->getNumInits() : CPLIE->getInitExprs().size();
 
 // If this is a multi-dimensional array new, we will initialize multiple
 // elements with each init list element.
@@ -1101,7 +1103,8 @@ void CodeGenFunction::EmitNewArrayInitializer(
 }
 
 CharUnits StartAlign = CurPtr.getAlignment();
-for (unsigned i = 0, e = ILE->getNumInits(); i != e; ++i) {
+ArrayRef InitExprs = ILE ? ILE->inits() : CPLIE->getInitExprs();
+for (unsigned i = 0; i < InitExprs.size(); ++i) {
   // Tell the cleanup that it needs to destroy up to this
   // element.  TODO: some of these stores can be trivially
   // observed to be unnecessary.
@@ -,8 +1114,8 @@ void CodeGenFunction::EmitNewArrayInitializer(
   // FIXME: If the last initializer is an incomplete initializer list for
   // an array, and we have an array filler, we can fold together the two
   // initialization loops.
-  StoreAnyExprIntoOneUnit(*this, ILE->getInit(i),
-  ILE->getInit(i)->getType(), CurPtr,
+  Expr *IE = InitExprs[i];
+  StoreAnyExprIntoOneUnit(*this, IE, IE->getType(), CurPtr,
   AggValueSlot::DoesNotOverlap);
   CurPtr = Address(Builder.CreateInBoundsGEP(
CurPtr.getElementType(), CurPtr.getPointer(),
@@ -1122,7 +1125,7 @@ void CodeGenFunction::EmitNewArrayInitializer(
 }
 
 // The remaining elements are filled with the array filler expression.
-Init = ILE->getArrayFiller();
+Init = ILE ? ILE->getArrayFiller() : CPLIE->getArrayFiller();
 
 // Extract the initializer for the individual array elements by pulling
 // out the array filler from all the nested initializer lists. This avoids
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 4ae04358d5df7c..71e420648ce7af 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -1947,11 +1947,11 @@ Sema::ActOnCXXNew(SourceLocation StartLoc, bool 
UseGlobal,
 }
 
 static bool isLegalArrayNewInitializer(CXXNewInitializationStyle Style,
-   

[clang] [clang] Fix parenthesized list initialization of arrays not working with `new` (PR #76976)

2024-01-09 Thread Alan Zhao via cfe-commits

https://github.com/alanzhao1 updated 
https://github.com/llvm/llvm-project/pull/76976

>From ee4e3c8634bb876166ee753a4ebcbf3c1699a175 Mon Sep 17 00:00:00 2001
From: Alan Zhao 
Date: Wed, 3 Jan 2024 12:29:21 -0800
Subject: [PATCH 1/6] [clang] Fix parenthesized list initialization of arrays
 not working with `new`

This bug is caused by parenthesized list initialization not being
implemented in `CodeGenFunction::EmitNewArrayInitializer(...)`.

Parenthesized list initialization of `struct`s  with `operator new`
already works in Clang and is not affected by this bug.

Additionally, fix the test new-delete.cpp as it incorrectly assumes that
using parentheses with operator new to initialize arrays is illegal for
C++ versions >= C++17.

Fixes #68198
---
 clang/docs/ReleaseNotes.rst|  3 +
 clang/lib/CodeGen/CGExprCXX.cpp| 17 ++---
 clang/lib/Sema/SemaExprCXX.cpp |  6 +-
 clang/test/CodeGen/paren-list-agg-init.cpp | 72 ++
 clang/test/SemaCXX/new-delete.cpp  | 20 +++---
 5 files changed, 98 insertions(+), 20 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c7bf162426a68c..211fd62a1ee85f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -844,6 +844,9 @@ Bug Fixes to C++ Support
 - Fix crash when parsing nested requirement. Fixes:
   (`#73112 `_)
 
+- Clang now allows parenthesized initialization of arrays in `operator new[]`.
+  Fixes: (`#68198 `_)
+
 Bug Fixes to AST Handling
 ^
 - Fixed an import failure of recursive friend class template.
diff --git a/clang/lib/CodeGen/CGExprCXX.cpp b/clang/lib/CodeGen/CGExprCXX.cpp
index 98ae56e2df8818..72c61bfb5ec344 100644
--- a/clang/lib/CodeGen/CGExprCXX.cpp
+++ b/clang/lib/CodeGen/CGExprCXX.cpp
@@ -1038,11 +1038,13 @@ void CodeGenFunction::EmitNewArrayInitializer(
 return true;
   };
 
+  const InitListExpr *ILE = dyn_cast(Init);
+  const CXXParenListInitExpr *CPLIE = dyn_cast(Init);
   // If the initializer is an initializer list, first do the explicit elements.
-  if (const InitListExpr *ILE = dyn_cast(Init)) {
+  if (ILE || CPLIE) {
 // Initializing from a (braced) string literal is a special case; the init
 // list element does not initialize a (single) array element.
-if (ILE->isStringLiteralInit()) {
+if (ILE && ILE->isStringLiteralInit()) {
   // Initialize the initial portion of length equal to that of the string
   // literal. The allocation must be for at least this much; we emitted a
   // check for that earlier.
@@ -1073,7 +1075,7 @@ void CodeGenFunction::EmitNewArrayInitializer(
   return;
 }
 
-InitListElements = ILE->getNumInits();
+InitListElements = ILE ? ILE->getNumInits() : CPLIE->getInitExprs().size();
 
 // If this is a multi-dimensional array new, we will initialize multiple
 // elements with each init list element.
@@ -1101,7 +1103,8 @@ void CodeGenFunction::EmitNewArrayInitializer(
 }
 
 CharUnits StartAlign = CurPtr.getAlignment();
-for (unsigned i = 0, e = ILE->getNumInits(); i != e; ++i) {
+ArrayRef InitExprs = ILE ? ILE->inits() : CPLIE->getInitExprs();
+for (unsigned i = 0; i < InitExprs.size(); ++i) {
   // Tell the cleanup that it needs to destroy up to this
   // element.  TODO: some of these stores can be trivially
   // observed to be unnecessary.
@@ -,8 +1114,8 @@ void CodeGenFunction::EmitNewArrayInitializer(
   // FIXME: If the last initializer is an incomplete initializer list for
   // an array, and we have an array filler, we can fold together the two
   // initialization loops.
-  StoreAnyExprIntoOneUnit(*this, ILE->getInit(i),
-  ILE->getInit(i)->getType(), CurPtr,
+  Expr *IE = InitExprs[i];
+  StoreAnyExprIntoOneUnit(*this, IE, IE->getType(), CurPtr,
   AggValueSlot::DoesNotOverlap);
   CurPtr = Address(Builder.CreateInBoundsGEP(
CurPtr.getElementType(), CurPtr.getPointer(),
@@ -1122,7 +1125,7 @@ void CodeGenFunction::EmitNewArrayInitializer(
 }
 
 // The remaining elements are filled with the array filler expression.
-Init = ILE->getArrayFiller();
+Init = ILE ? ILE->getArrayFiller() : CPLIE->getArrayFiller();
 
 // Extract the initializer for the individual array elements by pulling
 // out the array filler from all the nested initializer lists. This avoids
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 4ae04358d5df7c..71e420648ce7af 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -1947,11 +1947,11 @@ Sema::ActOnCXXNew(SourceLocation StartLoc, bool 
UseGlobal,
 }
 
 static bool isLegalArrayNewInitializer(CXXNewInitializationStyle Style,
-   

[clang] [clang] Fix parenthesized list initialization of arrays not working with `new` (PR #76976)

2024-01-09 Thread Alan Zhao via cfe-commits


@@ -5495,14 +5495,12 @@ static void TryOrBuildParenListInitialization(
 return;
 }
 //   ...and value-initialized for each k < i <= n;
-if (ArrayLength > Args.size()) {

alanzhao1 wrote:

> What is this change supposed to do?

`CodeGenFunction::EmitNewArrayInitializer(...)` needs an array filler for 
dynamic-sized arrays - e.g.

```cpp
void foo(int n) {
  new int[n](1, 2);
}
```

> The existing code is intentionally trying to avoid creating an array filler 
> if it won't be used (so, for example, the code will compile if the default 
> constructor is deleted).

Thanks for pointing this out! There was no test for this case with a deleted 
constructor, so I'll have to create a separate PR to add one later.

In the meantime, I resolved this by adding `Entity.isVariableLengthArrayNew()` 
to the conditional here. This is also what we do in `InitListChecker` to detect 
this condition.


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


[clang] [clang] Fix parenthesized list initialization of arrays not working with `new` (PR #76976)

2024-01-09 Thread Alan Zhao via cfe-commits


@@ -1038,11 +1038,14 @@ void CodeGenFunction::EmitNewArrayInitializer(
 return true;
   };
 
+  const InitListExpr *ILE = dyn_cast(Init);
+  const CXXParenListInitExpr *CPLIE = dyn_cast(Init);
+  const StringLiteral *SL = dyn_cast(Init);
   // If the initializer is an initializer list, first do the explicit elements.
-  if (const InitListExpr *ILE = dyn_cast(Init)) {
+  if (ILE || CPLIE || SL) {

alanzhao1 wrote:

This is parsed as a `StringLiteral` as shown in the AST.

`new-array.cc`:

```cpp
char* x = new char[]("asdf");
```

```
$ ./bin/clang -Xclang -ast-dump -std=c++20 ~/src/tests/new-array.cc

(irrelevant bits omitted)

|-VarDecl 0x557ce6fee8c0 
 col:7 x 
'char *' cinit
| `-CXXNewExpr 0x557ce700cca0  'char *' array Function 
0x557ce6fef0a0 'operator new[]' 'void *(unsigned long)'
|   |-IntegerLiteral 0x557ce700cc50  'unsigned long' 5
|   `-StringLiteral 0x557ce6feea00  'char[5]' "asdf"
```

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


[clang] [nfc][clang] Fix test in new-array-init.cpp (PR #79225)

2024-01-23 Thread Alan Zhao via cfe-commits

https://github.com/alanzhao1 created 
https://github.com/llvm/llvm-project/pull/79225

This test was originally introduced in
https://github.com/llvm/llvm-project/pull/76976, but it incorrectly tests 
braced-list initialization instead of parenthesized initialization.

>From e68891368098b2ea4883594cfa720ca4ac6ac435 Mon Sep 17 00:00:00 2001
From: Alan Zhao 
Date: Tue, 23 Jan 2024 15:24:35 -0800
Subject: [PATCH] [nfc][clang] Fix test in new-array-init.cpp

This test was originally introduced in
https://github.com/llvm/llvm-project/pull/76976, but it incorrectly
tests braced-list initialization instead of parenthesized
initialization.
---
 clang/test/CodeGenCXX/new-array-init.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/CodeGenCXX/new-array-init.cpp 
b/clang/test/CodeGenCXX/new-array-init.cpp
index fe1bdf425ab142..781c4728df4509 100644
--- a/clang/test/CodeGenCXX/new-array-init.cpp
+++ b/clang/test/CodeGenCXX/new-array-init.cpp
@@ -164,7 +164,7 @@ void string_sufficient_paren() {
   // FIXME: For very large arrays, it would be preferable to emit a small copy 
and a memset.
   // CHECKCXX20: call void @llvm.memcpy{{.*}}(ptr align {{[0-9]+}} %[[PTR]], 
ptr align {{[0-9]+}} @[[ABC15]], i32 15,
   // CHECKCXX20-NOT: memset
-  new char[15] { "abc" };
+  new char[15]("abc");
 }
 #endif
 

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


[clang] [nfc][clang] Fix test in new-array-init.cpp (PR #79225)

2024-01-23 Thread Alan Zhao via cfe-commits

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


[clang] [clang] Fix direct-initialization with new expressions for arrays (PR #78201)

2024-01-15 Thread Alan Zhao via cfe-commits

alanzhao1 wrote:

> I believe the approach here is not sufficient and we have a current PR in 
> progress: #76976
> 
> we also need codegen work to implement this.

Correct - here are some examples that will cause this to fail:

```cpp
void foo(int n) {
  new int[n](1, 2);
}
```

```cpp
void bar() {
  new char[]("abcd");
}
```


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


[clang] [clang] Fix parenthesized list initialization of arrays not working with `new` (PR #76976)

2024-01-16 Thread Alan Zhao via cfe-commits

alanzhao1 wrote:

Ping. Any more comments?

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


[clang] [clang] Fix parenthesized list initialization of arrays not working with `new` (PR #76976)

2024-01-16 Thread Alan Zhao via cfe-commits


@@ -1038,11 +1038,14 @@ void CodeGenFunction::EmitNewArrayInitializer(
 return true;
   };
 
+  const InitListExpr *ILE = dyn_cast(Init);
+  const CXXParenListInitExpr *CPLIE = dyn_cast(Init);
+  const StringLiteral *SL = dyn_cast(Init);
   // If the initializer is an initializer list, first do the explicit elements.
-  if (const InitListExpr *ILE = dyn_cast(Init)) {
+  if (ILE || CPLIE || SL) {

alanzhao1 wrote:

Thanks again for catching these - they both cause crashes.

For the `__extension__` example, we have a `StringLiteral` wrapped in a 
`UnaryOperator`

```
|-VarDecl 0x561d5f1ba190 
 col:7 x 
'char *' cinit
| `-CXXNewExpr 0x561d5f1d8580  'char *' array Function 
0x561d5f1ba990 'operator new[]' 'void *(unsigned long)'
|   |-IntegerLiteral 0x561d5f1d8530  'unsigned long' 5
|   `-UnaryOperator 0x561d5f1ba2f0  'char[5]' prefix 
'__extension__' cannot overflow
| `-StringLiteral 0x561d5f1ba2d0  'char[5]' "asdf"
```

and for the Objective-C++ example, we have a `ObjCEncodeExpr`:

```
|-VarDecl 0x55b8a4d0a150 
 col:7 x 'char 
*' cinit
| `-CXXNewExpr 0x55b8a4d2a560  'char *' array Function 
0x55b8a4d0a940 'operator new[]' 'void *(unsigned long)'
|   |-IntegerLiteral 0x55b8a4d2a510  'unsigned long' 2
|   `-ObjCEncodeExpr 0x55b8a4d0a2a0  'char[2]' 'int'
```

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


[clang] [clang] Fix parenthesized list initialization of arrays not working with `new` (PR #76976)

2024-01-16 Thread Alan Zhao via cfe-commits


@@ -1038,11 +1038,14 @@ void CodeGenFunction::EmitNewArrayInitializer(
 return true;
   };
 
+  const InitListExpr *ILE = dyn_cast(Init);
+  const CXXParenListInitExpr *CPLIE = dyn_cast(Init);
+  const StringLiteral *SL = dyn_cast(Init);
   // If the initializer is an initializer list, first do the explicit elements.
-  if (const InitListExpr *ILE = dyn_cast(Init)) {
+  if (ILE || CPLIE || SL) {

alanzhao1 wrote:

OK, I've implemented a fix for this locally (but I haven't pushed my branch yet 
as I haven't written tests).

I'm running into a problem with the example:

```objc
char* x = new char[](@encode(int));
```

Clang produces the error:

```
$ bin/clang++ -c -o - -S -emit-llvm -std=c++20 ~/src/tests/encode.mii
/usr/local/google/home/ayzhao/src/tests/encode.mii:1:28: error: cannot compile 
this aggregate expression yet
1 | const char* x = new char[](@encode(int));
  |^~~~
1 error generated.
```

Clang emits the same error for a braced initialization-list:

```
$ bin/clang++ -c -o - -S -emit-llvm -std=c++20 ~/src/tests/encode.mii
/usr/local/google/home/ayzhao/src/tests/encode.mii:1:28: error: cannot compile 
this aggregate expression yet
1 | const char* x = new char[]{@encode(int)};
  |^~~~
1 error generated.
```

while GCC happily compiles both examples: https://godbolt.org/z/494x4ne5o

Given that braced initialization of a `ObjCEncodeExpr` is already broken in 
clang, I'm leaning towards maintaining the same behavior between clang's 
braced-initialization and parenthesized initialization here, but if others have 
any other ideas, I'm happy to hear them.

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


[clang] [clang] Fix parenthesized list initialization of arrays not working with `new` (PR #76976)

2024-01-16 Thread Alan Zhao via cfe-commits

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


[clang] [clang] Fix parenthesized list initialization of arrays not working with `new` (PR #76976)

2024-01-16 Thread Alan Zhao via cfe-commits

https://github.com/alanzhao1 updated 
https://github.com/llvm/llvm-project/pull/76976

>From ee4e3c8634bb876166ee753a4ebcbf3c1699a175 Mon Sep 17 00:00:00 2001
From: Alan Zhao 
Date: Wed, 3 Jan 2024 12:29:21 -0800
Subject: [PATCH 1/7] [clang] Fix parenthesized list initialization of arrays
 not working with `new`

This bug is caused by parenthesized list initialization not being
implemented in `CodeGenFunction::EmitNewArrayInitializer(...)`.

Parenthesized list initialization of `struct`s  with `operator new`
already works in Clang and is not affected by this bug.

Additionally, fix the test new-delete.cpp as it incorrectly assumes that
using parentheses with operator new to initialize arrays is illegal for
C++ versions >= C++17.

Fixes #68198
---
 clang/docs/ReleaseNotes.rst|  3 +
 clang/lib/CodeGen/CGExprCXX.cpp| 17 ++---
 clang/lib/Sema/SemaExprCXX.cpp |  6 +-
 clang/test/CodeGen/paren-list-agg-init.cpp | 72 ++
 clang/test/SemaCXX/new-delete.cpp  | 20 +++---
 5 files changed, 98 insertions(+), 20 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c7bf162426a68c..211fd62a1ee85f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -844,6 +844,9 @@ Bug Fixes to C++ Support
 - Fix crash when parsing nested requirement. Fixes:
   (`#73112 `_)
 
+- Clang now allows parenthesized initialization of arrays in `operator new[]`.
+  Fixes: (`#68198 `_)
+
 Bug Fixes to AST Handling
 ^
 - Fixed an import failure of recursive friend class template.
diff --git a/clang/lib/CodeGen/CGExprCXX.cpp b/clang/lib/CodeGen/CGExprCXX.cpp
index 98ae56e2df8818..72c61bfb5ec344 100644
--- a/clang/lib/CodeGen/CGExprCXX.cpp
+++ b/clang/lib/CodeGen/CGExprCXX.cpp
@@ -1038,11 +1038,13 @@ void CodeGenFunction::EmitNewArrayInitializer(
 return true;
   };
 
+  const InitListExpr *ILE = dyn_cast(Init);
+  const CXXParenListInitExpr *CPLIE = dyn_cast(Init);
   // If the initializer is an initializer list, first do the explicit elements.
-  if (const InitListExpr *ILE = dyn_cast(Init)) {
+  if (ILE || CPLIE) {
 // Initializing from a (braced) string literal is a special case; the init
 // list element does not initialize a (single) array element.
-if (ILE->isStringLiteralInit()) {
+if (ILE && ILE->isStringLiteralInit()) {
   // Initialize the initial portion of length equal to that of the string
   // literal. The allocation must be for at least this much; we emitted a
   // check for that earlier.
@@ -1073,7 +1075,7 @@ void CodeGenFunction::EmitNewArrayInitializer(
   return;
 }
 
-InitListElements = ILE->getNumInits();
+InitListElements = ILE ? ILE->getNumInits() : CPLIE->getInitExprs().size();
 
 // If this is a multi-dimensional array new, we will initialize multiple
 // elements with each init list element.
@@ -1101,7 +1103,8 @@ void CodeGenFunction::EmitNewArrayInitializer(
 }
 
 CharUnits StartAlign = CurPtr.getAlignment();
-for (unsigned i = 0, e = ILE->getNumInits(); i != e; ++i) {
+ArrayRef InitExprs = ILE ? ILE->inits() : CPLIE->getInitExprs();
+for (unsigned i = 0; i < InitExprs.size(); ++i) {
   // Tell the cleanup that it needs to destroy up to this
   // element.  TODO: some of these stores can be trivially
   // observed to be unnecessary.
@@ -,8 +1114,8 @@ void CodeGenFunction::EmitNewArrayInitializer(
   // FIXME: If the last initializer is an incomplete initializer list for
   // an array, and we have an array filler, we can fold together the two
   // initialization loops.
-  StoreAnyExprIntoOneUnit(*this, ILE->getInit(i),
-  ILE->getInit(i)->getType(), CurPtr,
+  Expr *IE = InitExprs[i];
+  StoreAnyExprIntoOneUnit(*this, IE, IE->getType(), CurPtr,
   AggValueSlot::DoesNotOverlap);
   CurPtr = Address(Builder.CreateInBoundsGEP(
CurPtr.getElementType(), CurPtr.getPointer(),
@@ -1122,7 +1125,7 @@ void CodeGenFunction::EmitNewArrayInitializer(
 }
 
 // The remaining elements are filled with the array filler expression.
-Init = ILE->getArrayFiller();
+Init = ILE ? ILE->getArrayFiller() : CPLIE->getArrayFiller();
 
 // Extract the initializer for the individual array elements by pulling
 // out the array filler from all the nested initializer lists. This avoids
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 4ae04358d5df7c..71e420648ce7af 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -1947,11 +1947,11 @@ Sema::ActOnCXXNew(SourceLocation StartLoc, bool 
UseGlobal,
 }
 
 static bool isLegalArrayNewInitializer(CXXNewInitializationStyle Style,
-   

[clang] [clang] Fix parenthesized list initialization of arrays not working with `new` (PR #76976)

2024-01-17 Thread Alan Zhao via cfe-commits

https://github.com/alanzhao1 updated 
https://github.com/llvm/llvm-project/pull/76976

>From ee4e3c8634bb876166ee753a4ebcbf3c1699a175 Mon Sep 17 00:00:00 2001
From: Alan Zhao 
Date: Wed, 3 Jan 2024 12:29:21 -0800
Subject: [PATCH 1/8] [clang] Fix parenthesized list initialization of arrays
 not working with `new`

This bug is caused by parenthesized list initialization not being
implemented in `CodeGenFunction::EmitNewArrayInitializer(...)`.

Parenthesized list initialization of `struct`s  with `operator new`
already works in Clang and is not affected by this bug.

Additionally, fix the test new-delete.cpp as it incorrectly assumes that
using parentheses with operator new to initialize arrays is illegal for
C++ versions >= C++17.

Fixes #68198
---
 clang/docs/ReleaseNotes.rst|  3 +
 clang/lib/CodeGen/CGExprCXX.cpp| 17 ++---
 clang/lib/Sema/SemaExprCXX.cpp |  6 +-
 clang/test/CodeGen/paren-list-agg-init.cpp | 72 ++
 clang/test/SemaCXX/new-delete.cpp  | 20 +++---
 5 files changed, 98 insertions(+), 20 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c7bf162426a68c..211fd62a1ee85f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -844,6 +844,9 @@ Bug Fixes to C++ Support
 - Fix crash when parsing nested requirement. Fixes:
   (`#73112 `_)
 
+- Clang now allows parenthesized initialization of arrays in `operator new[]`.
+  Fixes: (`#68198 `_)
+
 Bug Fixes to AST Handling
 ^
 - Fixed an import failure of recursive friend class template.
diff --git a/clang/lib/CodeGen/CGExprCXX.cpp b/clang/lib/CodeGen/CGExprCXX.cpp
index 98ae56e2df8818..72c61bfb5ec344 100644
--- a/clang/lib/CodeGen/CGExprCXX.cpp
+++ b/clang/lib/CodeGen/CGExprCXX.cpp
@@ -1038,11 +1038,13 @@ void CodeGenFunction::EmitNewArrayInitializer(
 return true;
   };
 
+  const InitListExpr *ILE = dyn_cast(Init);
+  const CXXParenListInitExpr *CPLIE = dyn_cast(Init);
   // If the initializer is an initializer list, first do the explicit elements.
-  if (const InitListExpr *ILE = dyn_cast(Init)) {
+  if (ILE || CPLIE) {
 // Initializing from a (braced) string literal is a special case; the init
 // list element does not initialize a (single) array element.
-if (ILE->isStringLiteralInit()) {
+if (ILE && ILE->isStringLiteralInit()) {
   // Initialize the initial portion of length equal to that of the string
   // literal. The allocation must be for at least this much; we emitted a
   // check for that earlier.
@@ -1073,7 +1075,7 @@ void CodeGenFunction::EmitNewArrayInitializer(
   return;
 }
 
-InitListElements = ILE->getNumInits();
+InitListElements = ILE ? ILE->getNumInits() : CPLIE->getInitExprs().size();
 
 // If this is a multi-dimensional array new, we will initialize multiple
 // elements with each init list element.
@@ -1101,7 +1103,8 @@ void CodeGenFunction::EmitNewArrayInitializer(
 }
 
 CharUnits StartAlign = CurPtr.getAlignment();
-for (unsigned i = 0, e = ILE->getNumInits(); i != e; ++i) {
+ArrayRef InitExprs = ILE ? ILE->inits() : CPLIE->getInitExprs();
+for (unsigned i = 0; i < InitExprs.size(); ++i) {
   // Tell the cleanup that it needs to destroy up to this
   // element.  TODO: some of these stores can be trivially
   // observed to be unnecessary.
@@ -,8 +1114,8 @@ void CodeGenFunction::EmitNewArrayInitializer(
   // FIXME: If the last initializer is an incomplete initializer list for
   // an array, and we have an array filler, we can fold together the two
   // initialization loops.
-  StoreAnyExprIntoOneUnit(*this, ILE->getInit(i),
-  ILE->getInit(i)->getType(), CurPtr,
+  Expr *IE = InitExprs[i];
+  StoreAnyExprIntoOneUnit(*this, IE, IE->getType(), CurPtr,
   AggValueSlot::DoesNotOverlap);
   CurPtr = Address(Builder.CreateInBoundsGEP(
CurPtr.getElementType(), CurPtr.getPointer(),
@@ -1122,7 +1125,7 @@ void CodeGenFunction::EmitNewArrayInitializer(
 }
 
 // The remaining elements are filled with the array filler expression.
-Init = ILE->getArrayFiller();
+Init = ILE ? ILE->getArrayFiller() : CPLIE->getArrayFiller();
 
 // Extract the initializer for the individual array elements by pulling
 // out the array filler from all the nested initializer lists. This avoids
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 4ae04358d5df7c..71e420648ce7af 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -1947,11 +1947,11 @@ Sema::ActOnCXXNew(SourceLocation StartLoc, bool 
UseGlobal,
 }
 
 static bool isLegalArrayNewInitializer(CXXNewInitializationStyle Style,
-   

[clang] [clang] Fix parenthesized list initialization of arrays not working with `new` (PR #76976)

2024-01-17 Thread Alan Zhao via cfe-commits

https://github.com/alanzhao1 updated 
https://github.com/llvm/llvm-project/pull/76976

>From ee4e3c8634bb876166ee753a4ebcbf3c1699a175 Mon Sep 17 00:00:00 2001
From: Alan Zhao 
Date: Wed, 3 Jan 2024 12:29:21 -0800
Subject: [PATCH 1/9] [clang] Fix parenthesized list initialization of arrays
 not working with `new`

This bug is caused by parenthesized list initialization not being
implemented in `CodeGenFunction::EmitNewArrayInitializer(...)`.

Parenthesized list initialization of `struct`s  with `operator new`
already works in Clang and is not affected by this bug.

Additionally, fix the test new-delete.cpp as it incorrectly assumes that
using parentheses with operator new to initialize arrays is illegal for
C++ versions >= C++17.

Fixes #68198
---
 clang/docs/ReleaseNotes.rst|  3 +
 clang/lib/CodeGen/CGExprCXX.cpp| 17 ++---
 clang/lib/Sema/SemaExprCXX.cpp |  6 +-
 clang/test/CodeGen/paren-list-agg-init.cpp | 72 ++
 clang/test/SemaCXX/new-delete.cpp  | 20 +++---
 5 files changed, 98 insertions(+), 20 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c7bf162426a68c..211fd62a1ee85f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -844,6 +844,9 @@ Bug Fixes to C++ Support
 - Fix crash when parsing nested requirement. Fixes:
   (`#73112 `_)
 
+- Clang now allows parenthesized initialization of arrays in `operator new[]`.
+  Fixes: (`#68198 `_)
+
 Bug Fixes to AST Handling
 ^
 - Fixed an import failure of recursive friend class template.
diff --git a/clang/lib/CodeGen/CGExprCXX.cpp b/clang/lib/CodeGen/CGExprCXX.cpp
index 98ae56e2df8818..72c61bfb5ec344 100644
--- a/clang/lib/CodeGen/CGExprCXX.cpp
+++ b/clang/lib/CodeGen/CGExprCXX.cpp
@@ -1038,11 +1038,13 @@ void CodeGenFunction::EmitNewArrayInitializer(
 return true;
   };
 
+  const InitListExpr *ILE = dyn_cast(Init);
+  const CXXParenListInitExpr *CPLIE = dyn_cast(Init);
   // If the initializer is an initializer list, first do the explicit elements.
-  if (const InitListExpr *ILE = dyn_cast(Init)) {
+  if (ILE || CPLIE) {
 // Initializing from a (braced) string literal is a special case; the init
 // list element does not initialize a (single) array element.
-if (ILE->isStringLiteralInit()) {
+if (ILE && ILE->isStringLiteralInit()) {
   // Initialize the initial portion of length equal to that of the string
   // literal. The allocation must be for at least this much; we emitted a
   // check for that earlier.
@@ -1073,7 +1075,7 @@ void CodeGenFunction::EmitNewArrayInitializer(
   return;
 }
 
-InitListElements = ILE->getNumInits();
+InitListElements = ILE ? ILE->getNumInits() : CPLIE->getInitExprs().size();
 
 // If this is a multi-dimensional array new, we will initialize multiple
 // elements with each init list element.
@@ -1101,7 +1103,8 @@ void CodeGenFunction::EmitNewArrayInitializer(
 }
 
 CharUnits StartAlign = CurPtr.getAlignment();
-for (unsigned i = 0, e = ILE->getNumInits(); i != e; ++i) {
+ArrayRef InitExprs = ILE ? ILE->inits() : CPLIE->getInitExprs();
+for (unsigned i = 0; i < InitExprs.size(); ++i) {
   // Tell the cleanup that it needs to destroy up to this
   // element.  TODO: some of these stores can be trivially
   // observed to be unnecessary.
@@ -,8 +1114,8 @@ void CodeGenFunction::EmitNewArrayInitializer(
   // FIXME: If the last initializer is an incomplete initializer list for
   // an array, and we have an array filler, we can fold together the two
   // initialization loops.
-  StoreAnyExprIntoOneUnit(*this, ILE->getInit(i),
-  ILE->getInit(i)->getType(), CurPtr,
+  Expr *IE = InitExprs[i];
+  StoreAnyExprIntoOneUnit(*this, IE, IE->getType(), CurPtr,
   AggValueSlot::DoesNotOverlap);
   CurPtr = Address(Builder.CreateInBoundsGEP(
CurPtr.getElementType(), CurPtr.getPointer(),
@@ -1122,7 +1125,7 @@ void CodeGenFunction::EmitNewArrayInitializer(
 }
 
 // The remaining elements are filled with the array filler expression.
-Init = ILE->getArrayFiller();
+Init = ILE ? ILE->getArrayFiller() : CPLIE->getArrayFiller();
 
 // Extract the initializer for the individual array elements by pulling
 // out the array filler from all the nested initializer lists. This avoids
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 4ae04358d5df7c..71e420648ce7af 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -1947,11 +1947,11 @@ Sema::ActOnCXXNew(SourceLocation StartLoc, bool 
UseGlobal,
 }
 
 static bool isLegalArrayNewInitializer(CXXNewInitializationStyle Style,
-   

[clang] [clang][Darwin] Remove legacy framework search path logic in the frontend (PR #75841)

2024-01-17 Thread Alan Zhao via cfe-commits

alanzhao1 wrote:

Here's what I did to repro:

`include.cc`:

```cpp
#include 
```

Build clang:
```
$ cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_LLD=False 
-DLLVM_CCACHE_BUILD=True -DLLVM_ENABLE_PROJECTS="clang" 
-DLLVM_TARGETS_TO_BUILD="X86;ARM;AArch64" ../llvm
$ ninja clang
```

I get the following error with this patch:
```
$ bin/clang -c -o /dev/null ~/src/tests/include.cc 
-isysroot/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/
/Users/ayzhao/src/tests/include.cc:1:10: fatal error: 
'CoreFoundation/CoreFoundation.h' file not found
1 | #include 
  |  ^
1 error generated.
```


System information:

```
$ xcodebuild -version
Xcode 13.4
Build version 13F17a
$ uname -a
Darwin ayzhao-macbookpro2.roam.internal 23.3.0 Darwin Kernel Version 23.3.0: 
Thu Jan  4 13:52:35 PST 2024; root:xnu-10002.81.5~13/RELEASE_ARM64_T6000 arm64
```

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


[clang] [clang][Darwin] Remove legacy framework search path logic in the frontend (PR #75841)

2024-01-17 Thread Alan Zhao via cfe-commits

alanzhao1 wrote:

If we pass `-v` to Clang, we get the following include directories:

without this patch:

```
clang -cc1 version 18.0.0git based upon LLVM 18.0.0git default target 
arm64-apple-darwin23.3.0
ignoring nonexistent directory 
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/local/include"
ignoring nonexistent directory 
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk//Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
 
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1
 /Users/ayzhao/src/llvm-project/build/lib/clang/18/include
 
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
 
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk//System/Library/Frameworks
 (framework directory)
End of search list.
```

with this patch:

```
clang -cc1 version 18.0.0git based upon LLVM 18.0.0git default target 
arm64-apple-darwin23.3.0
ignoring nonexistent directory 
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/local/include"
#include "..." search starts here:
#include <...> search starts here:
 
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1
 /Users/ayzhao/src/llvm-project/build/lib/clang/18/include
 
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
End of search list.
```

So it looks like this patch causes Clang to think that the directory 
`/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk//Library/Frameworks`
 exists when it doesn't.

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


[clang] [clang] Fix parenthesized list initialization of arrays not working with `new` (PR #76976)

2024-01-18 Thread Alan Zhao via cfe-commits

https://github.com/alanzhao1 updated 
https://github.com/llvm/llvm-project/pull/76976

>From 1ac47a1548f0dbd21747ef05c64fc2f08668e0e1 Mon Sep 17 00:00:00 2001
From: Alan Zhao 
Date: Wed, 3 Jan 2024 12:29:21 -0800
Subject: [PATCH] [clang] Fix parenthesized list initialization of arrays not
 working with `new`

This bug is caused by parenthesized list initialization not being
implemented in `CodeGenFunction::EmitNewArrayInitializer(...)`.

Parenthesized list initialization of `struct`s  with `operator new`
already works in Clang and is not affected by this bug.

Additionally, fix the test new-delete.cpp as it incorrectly assumes that
using parentheses with operator new to initialize arrays is illegal for
C++ versions >= C++17.

Fixes #68198
---
 clang/docs/ReleaseNotes.rst|  3 +
 clang/lib/CodeGen/CGExprCXX.cpp| 60 +-
 clang/lib/Sema/SemaExprCXX.cpp |  7 +-
 clang/lib/Sema/SemaInit.cpp|  2 +-
 clang/test/CodeGen/paren-list-agg-init.cpp | 57 +
 clang/test/CodeGenCXX/new-array-init.cpp   | 94 +-
 clang/test/SemaCXX/new-delete.cpp  | 31 ---
 7 files changed, 221 insertions(+), 33 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 0ea6f93a1f5df9d..b400d75095421c7 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -976,6 +976,9 @@ Bug Fixes to C++ Support
   ``std::source_location::current()`` was used in a function template.
   Fixes (`#78128 `_)
 
+- Clang now allows parenthesized initialization of arrays in `operator new[]`.
+  Fixes: (`#68198 `_)
+
 Bug Fixes to AST Handling
 ^
 - Fixed an import failure of recursive friend class template.
diff --git a/clang/lib/CodeGen/CGExprCXX.cpp b/clang/lib/CodeGen/CGExprCXX.cpp
index 98ae56e2df88184..d136bfc37278f0a 100644
--- a/clang/lib/CodeGen/CGExprCXX.cpp
+++ b/clang/lib/CodeGen/CGExprCXX.cpp
@@ -1038,11 +1038,25 @@ void CodeGenFunction::EmitNewArrayInitializer(
 return true;
   };
 
+  const InitListExpr *ILE = dyn_cast(Init);
+  const CXXParenListInitExpr *CPLIE = nullptr;
+  const StringLiteral *SL = nullptr;
+  const ObjCEncodeExpr *OCEE = nullptr;
+  const Expr *IgnoreParen = nullptr;
+  if (!ILE) {
+IgnoreParen = Init->IgnoreParenImpCasts();
+CPLIE = dyn_cast(IgnoreParen);
+SL = dyn_cast(IgnoreParen);
+OCEE = dyn_cast(IgnoreParen);
+  }
+
   // If the initializer is an initializer list, first do the explicit elements.
-  if (const InitListExpr *ILE = dyn_cast(Init)) {
+  if (ILE || CPLIE || SL || OCEE) {
 // Initializing from a (braced) string literal is a special case; the init
 // list element does not initialize a (single) array element.
-if (ILE->isStringLiteralInit()) {
+if ((ILE && ILE->isStringLiteralInit()) || SL || OCEE) {
+  if (!ILE)
+Init = IgnoreParen;
   // Initialize the initial portion of length equal to that of the string
   // literal. The allocation must be for at least this much; we emitted a
   // check for that earlier.
@@ -1054,12 +1068,13 @@ void CodeGenFunction::EmitNewArrayInitializer(
 AggValueSlot::DoesNotOverlap,
 AggValueSlot::IsNotZeroed,
 AggValueSlot::IsSanitizerChecked);
-  EmitAggExpr(ILE->getInit(0), Slot);
+  EmitAggExpr(ILE ? ILE->getInit(0) : Init, Slot);
 
   // Move past these elements.
   InitListElements =
-  cast(ILE->getType()->getAsArrayTypeUnsafe())
-  ->getSize().getZExtValue();
+  cast(Init->getType()->getAsArrayTypeUnsafe())
+  ->getSize()
+  .getZExtValue();
   CurPtr = Builder.CreateConstInBoundsGEP(
   CurPtr, InitListElements, "string.init.end");
 
@@ -1073,7 +1088,9 @@ void CodeGenFunction::EmitNewArrayInitializer(
   return;
 }
 
-InitListElements = ILE->getNumInits();
+ArrayRef InitExprs =
+ILE ? ILE->inits() : CPLIE->getInitExprs();
+InitListElements = InitExprs.size();
 
 // If this is a multi-dimensional array new, we will initialize multiple
 // elements with each init list element.
@@ -1101,7 +1118,8 @@ void CodeGenFunction::EmitNewArrayInitializer(
 }
 
 CharUnits StartAlign = CurPtr.getAlignment();
-for (unsigned i = 0, e = ILE->getNumInits(); i != e; ++i) {
+unsigned i = 0;
+for (const Expr *IE : InitExprs) {
   // Tell the cleanup that it needs to destroy up to this
   // element.  TODO: some of these stores can be trivially
   // observed to be unnecessary.
@@ -,18 +1129,17 @@ void CodeGenFunction::EmitNewArrayInitializer(
   // FIXME: If the last initializer is an incomplete initializer list for
   // an array, and we have an array filler, we can fold together the two
   // init

[clang] [clang] Fix parenthesized list initialization of arrays not working with `new` (PR #76976)

2024-01-18 Thread Alan Zhao via cfe-commits

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


[clang] ff8aadf - [clang][diagnostics] Don't warn about unreachable code in constexpr if

2022-08-15 Thread Alan Zhao via cfe-commits

Author: Alan Zhao
Date: 2022-08-15T15:24:39-04:00
New Revision: ff8aadf58d1a0ea7d8fa2b9a7a17ff0c6059baa5

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

LOG: [clang][diagnostics] Don't warn about unreachable code in constexpr if

The point of a constexpr if statement is to determine which branch to
take at compile time, so warning on unreachable code is meaningless in
these situations.

Fixes #57123.

Reviewed By: thakis

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

Added: 


Modified: 
clang/lib/Analysis/ReachableCode.cpp
clang/test/SemaCXX/unreachable-code.cpp

Removed: 




diff  --git a/clang/lib/Analysis/ReachableCode.cpp 
b/clang/lib/Analysis/ReachableCode.cpp
index 652bef34cebb7..ce0f4f83ba04f 100644
--- a/clang/lib/Analysis/ReachableCode.cpp
+++ b/clang/lib/Analysis/ReachableCode.cpp
@@ -299,6 +299,12 @@ static bool shouldTreatSuccessorsAsReachable(const 
CFGBlock *B,
 if (isa(Term)) {
   return isConfigurationValue(Term, PP);
 }
+// Do not treat constexpr if statement successors as unreachable in 
warnings
+// since the point of these statements is to determine branches at compile
+// time.
+if (const auto *IS = dyn_cast(Term);
+IS != nullptr && IS->isConstexpr())
+  return true;
   }
 
   const Stmt *Cond = B->getTerminatorCondition(/* stripParens */ false);

diff  --git a/clang/test/SemaCXX/unreachable-code.cpp 
b/clang/test/SemaCXX/unreachable-code.cpp
index 6a95f767bef02..410ed9ae8861b 100644
--- a/clang/test/SemaCXX/unreachable-code.cpp
+++ b/clang/test/SemaCXX/unreachable-code.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only 
-Wunreachable-code-aggressive -fblocks -verify %s
+// RUN: %clang_cc1 -std=c++17 -fcxx-exceptions -fexceptions -fsyntax-only 
-Wunreachable-code-aggressive -fblocks -verify %s
 
 int j;
 int bar();
@@ -99,3 +99,34 @@ void f(int a) {
 }
 
 }
+
+namespace gh57123 {
+  bool foo() {
+if constexpr (true) {
+  if (true)
+return true;
+  else
+return false; // expected-warning {{will never be executed}}
+}
+else
+  return false; // no-warning
+  }
+
+  bool bar() {
+if (true)
+  return true;
+else
+  return false; // expected-warning {{will never be executed}}
+  }
+
+  bool baz() {
+if constexpr (true)
+  return true;
+else {
+  if (true)
+return true;
+  else
+return false; // expected-warning {{will never be executed}}
+}
+  }
+}



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


[clang] 6f2b347 - Add missing `struct` keyword to the test p2-2.cpp

2022-09-28 Thread Alan Zhao via cfe-commits

Author: Alan Zhao
Date: 2022-09-28T09:48:00-07:00
New Revision: 6f2b34789541ff95d7f339eac5dc031d29655a58

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

LOG: Add missing `struct` keyword to the test p2-2.cpp

While working on D53847, I noticed that this test would fail once we
started recognizing the types in the modified `export` statement [0].
The tests would fail because Clang would emit a "declaration does not
declare anything" diagnostic instead of the expected namespace scope
diagnostic.

I believe that the test is currently incorrectly passing because Clang
doesn't parse the type and therefore doesn't treat the statement as a
declaration. My understanding is that the intention of this test case is
that it wants to export a `struct` type, which I believe requires a
`struct` keyword, even for types with template parameters. With this
change, the only error with these two statements should be the
namespace scope issue.

[0]: https://reviews.llvm.org/D53847?id=462032#inline-1297053

Reviewed By: erichkeane

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

Added: 


Modified: 
clang/test/CXX/module/module.interface/p2-2.cpp

Removed: 




diff  --git a/clang/test/CXX/module/module.interface/p2-2.cpp 
b/clang/test/CXX/module/module.interface/p2-2.cpp
index 359e068d230af..04904a8d86f27 100644
--- a/clang/test/CXX/module/module.interface/p2-2.cpp
+++ b/clang/test/CXX/module/module.interface/p2-2.cpp
@@ -14,7 +14,7 @@ struct X {
   U bar();
 };
 
-export template  X::iterator;  // 
expected-error {{cannot export 'iterator' as it is not at namespace scope}}
+export template  struct X::iterator;   // 
expected-error {{cannot export 'iterator' as it is not at namespace scope}}
 export template  void X::foo();// 
expected-error {{cannot export 'foo' as it is not at namespace scope}}
 export template  template  U X::bar(); // 
expected-error {{cannot export 'bar' as it is not at namespace scope}}
 
@@ -32,6 +32,6 @@ export void Y::foo();// expected-error 
{{cannot export 'foo'
 export template  U Y::bar(); // expected-error {{cannot export 
'bar' as it is not at namespace scope}}
 
 export {
-  template  X::iterator; // expected-error {{cannot export 
'iterator' as it is not at namespace scope}}
-  struct Y::iterator;   // expected-error {{cannot export 
'iterator' as it is not at namespace scope}}
+  template  struct X::iterator; // expected-error {{cannot 
export 'iterator' as it is not at namespace scope}}
+  struct Y::iterator;  // expected-error {{cannot 
export 'iterator' as it is not at namespace scope}}
 }



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


[clang] 4848f3b - [C++2a] P0634r3: Down with typename!

2022-09-28 Thread Alan Zhao via cfe-commits

Author: Nicolas Lesser
Date: 2022-09-28T09:50:19-07:00
New Revision: 4848f3bf2ff5ec57a8e2b8d3676c947dcf0fd735

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

LOG: [C++2a] P0634r3: Down with typename!

This patch implements P0634r3 that removes the need for 'typename' in certain 
contexts.

For example,

```
template 
using foo = T::type; // ok
```

This is also allowed in previous language versions as an extension, because I 
think it's pretty useful. :)

Reviewed By: #clang-language-wg, erichkeane

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

Added: 
clang/test/CXX/temp/temp.res/p4.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Parse/Parser.h
clang/include/clang/Sema/DeclSpec.h
clang/include/clang/Sema/Sema.h
clang/lib/Parse/ParseDecl.cpp
clang/lib/Parse/ParseDeclCXX.cpp
clang/lib/Parse/ParseExpr.cpp
clang/lib/Parse/ParseExprCXX.cpp
clang/lib/Parse/ParseTemplate.cpp
clang/lib/Parse/ParseTentative.cpp
clang/lib/Parse/Parser.cpp
clang/lib/Sema/Sema.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaTemplate.cpp
clang/test/CXX/basic/basic.lookup/basic.lookup.qual/class.qual/p2.cpp
clang/test/CXX/drs/dr1xx.cpp
clang/test/CXX/drs/dr2xx.cpp
clang/test/CXX/drs/dr4xx.cpp
clang/test/CXX/drs/dr5xx.cpp
clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
clang/test/CXX/temp/temp.res/p3.cpp
clang/test/CXX/temp/temp.res/temp.dep/temp.dep.type/p1.cpp
clang/test/FixIt/fixit.cpp
clang/test/Parser/cxx-member-initializers.cpp
clang/test/SemaCXX/MicrosoftCompatibility.cpp
clang/test/SemaCXX/MicrosoftExtensions.cpp
clang/test/SemaCXX/MicrosoftSuper.cpp
clang/test/SemaCXX/rounding-math-crash.cpp
clang/test/SemaCXX/typo-correction.cpp
clang/test/SemaCXX/unknown-type-name.cpp
clang/test/SemaTemplate/alias-templates.cpp
clang/test/SemaTemplate/typename-specifier-3.cpp
clang/www/cxx_status.html

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ee31da39d1978..b82aec630287b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -358,6 +358,8 @@ C++20 Feature Support
   `Issue 44178 `_.
 - Clang implements DR2621, correcting a defect in ``using enum`` handling.  The
   name is found via ordinary lookup so typedefs are found.
+- Implemented `P0634r3 
`_,
+  which removes the requirement for the ``typename`` keyword in certain 
contexts.
 
 C++2b Feature Support
 ^

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 2b544928ab763..1484622d8f8ae 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5432,6 +5432,12 @@ def err_typename_refers_to_using_value_decl : Error<
   "%0 in %1">;
 def note_using_value_decl_missing_typename : Note<
   "add 'typename' to treat this using declaration as a type">;
+def warn_cxx17_compat_implicit_typename : Warning<"use of implicit 'typename' 
is "
+  "incompatible with C++ standards before C++20">, InGroup,
+  DefaultIgnore;
+def ext_implicit_typename : ExtWarn<"missing 'typename' prior to dependent "
+  "type name %0%1; implicit 'typename' is a C++20 extension">,
+  InGroup;
 
 def err_template_kw_refers_to_non_template : Error<
   "%0%select{| following the 'template' keyword}1 "

diff  --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index e6144ae01c779..cb396b8b54122 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -857,9 +857,12 @@ class Parser : public CodeCompletionHandler {
 public:
   // If NeedType is true, then TryAnnotateTypeOrScopeToken will try harder to
   // find a type name by attempting typo correction.
-  bool TryAnnotateTypeOrScopeToken();
-  bool TryAnnotateTypeOrScopeTokenAfterScopeSpec(CXXScopeSpec &SS,
- bool IsNewScope);
+  bool
+  TryAnnotateTypeOrScopeToken(ImplicitTypenameContext AllowImplicitTypename =
+  ImplicitTypenameContext::No);
+  bool TryAnnotateTypeOrScopeTokenAfterScopeSpec(
+  CXXScopeSpec &SS, bool IsNewScope,
+  ImplicitTypenameContext AllowImplicitTypename);
   bool TryAnnotateCXXScopeToken(bool EnteringContext = false);
 
   bool MightBeCXXScopeToken() {
@@ -885,7 +888,11 @@ class Parser : public CodeCompletionHandler {
 /// Annotation was successful.
 ANK_Success
   };
-  AnnotatedNameKind TryAnnotateN

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

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

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

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

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

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

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

Reviewed By: ilya-biryukov

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

Added: 


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

Removed: 




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

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



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


[clang] 4e02ff2 - [clang] Revert parentesized aggregate initalization patches

2023-01-04 Thread Alan Zhao via cfe-commits

Author: Alan Zhao
Date: 2023-01-04T15:09:36-08:00
New Revision: 4e02ff2303f8a69cc2459b77bbb879b248df6ca9

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

LOG: [clang] Revert parentesized aggregate initalization patches

This feature causes clang to crash when compiling Chrome - see
https://crbug.com/1405031 and
https://github.com/llvm/llvm-project/issues/59675

Revert "[clang] Fix a clang crash on invalid code in C++20 mode."

This reverts commit 32d7aae04fdb58e65a952f281ff2f2c3f396d98f.

Revert "[clang] Remove overly restrictive aggregate paren init logic"

This reverts commit c77a91bb7ba793ec3a6a5da3743ed55056291658.

Revert "[clang][C++20] P0960R3 and P1975R0: Allow initializing aggregates from 
a parenthesized list of values"

This reverts commit 40c52159d3ee337dbed14e4c73b5616ea354c337.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang-c/Index.h
clang/include/clang/AST/ASTNodeTraverser.h
clang/include/clang/AST/ComputeDependence.h
clang/include/clang/AST/Decl.h
clang/include/clang/AST/ExprCXX.h
clang/include/clang/AST/RecursiveASTVisitor.h
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Basic/StmtNodes.td
clang/include/clang/Sema/Initialization.h
clang/include/clang/Serialization/ASTBitCodes.h
clang/lib/AST/ComputeDependence.cpp
clang/lib/AST/Expr.cpp
clang/lib/AST/ExprCXX.cpp
clang/lib/AST/ExprClassification.cpp
clang/lib/AST/ExprConstant.cpp
clang/lib/AST/ItaniumMangle.cpp
clang/lib/AST/JSONNodeDumper.cpp
clang/lib/AST/StmtPrinter.cpp
clang/lib/AST/StmtProfile.cpp
clang/lib/AST/TextNodeDumper.cpp
clang/lib/CodeGen/CGExprAgg.cpp
clang/lib/Frontend/InitPreprocessor.cpp
clang/lib/Sema/SemaCast.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaExceptionSpec.cpp
clang/lib/Sema/SemaInit.cpp
clang/lib/Sema/TreeTransform.h
clang/lib/Serialization/ASTReaderStmt.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/lib/Serialization/ASTWriterStmt.cpp
clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
clang/test/CXX/temp/temp.decls/temp.variadic/p4.cpp
clang/test/Lexer/cxx-features.cpp
clang/test/SemaCXX/cxx2a-explicit-bool.cpp
clang/test/SemaCXX/recovery-expr-type.cpp
clang/tools/libclang/CIndex.cpp
clang/tools/libclang/CXCursor.cpp
clang/www/cxx_status.html

Removed: 
clang/test/CodeGen/paren-list-agg-init.cpp
clang/test/PCH/cxx_paren_init.cpp
clang/test/PCH/cxx_paren_init.h
clang/test/SemaCXX/paren-list-agg-init.cpp



diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 0fe0097400823..a3abdf45fead1 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -714,10 +714,6 @@ C++20 Feature Support
   (useful specially for constrained members). Fixes `GH50886 
`_.
 - Implemented CWG2635 as a Defect Report, which prohibits structured bindings 
from being constrained.
 
-- Implemented `P0960R3: 
`_
-  and `P1975R0: 
`_,
-  which allows parenthesized aggregate-initialization.
-
 C++2b Feature Support
 ^
 

diff  --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h
index fd758ddde085d..5260085021928 100644
--- a/clang/include/clang-c/Index.h
+++ b/clang/include/clang-c/Index.h
@@ -1531,13 +1531,7 @@ enum CXCursorKind {
*/
   CXCursor_RequiresExpr = 154,
 
-  /**
-   * Expression that references a C++20 parenthesized list aggregate
-   * initializer.
-   */
-  CXCursor_CXXParenListInitExpr = 155,
-
-  CXCursor_LastExpr = CXCursor_CXXParenListInitExpr,
+  CXCursor_LastExpr = CXCursor_RequiresExpr,
 
   /* Statements */
   CXCursor_FirstStmt = 200,

diff  --git a/clang/include/clang/AST/ASTNodeTraverser.h 
b/clang/include/clang/AST/ASTNodeTraverser.h
index cc60877805f98..151a9c6b58524 100644
--- a/clang/include/clang/AST/ASTNodeTraverser.h
+++ b/clang/include/clang/AST/ASTNodeTraverser.h
@@ -710,12 +710,6 @@ class ASTNodeTraverser
 }
   }
 
-  void VisitCXXParenListInitExpr(const CXXParenListInitExpr *PLIE) {
-if (auto *Filler = PLIE->getArrayFiller()) {
-  Visit(Filler, "array_filler");
-}
-  }
-
   void VisitBlockExpr(const BlockExpr *Node) { Visit(Node->getBlockDecl()); }
 
   void VisitOpaqueValueExpr(const OpaqueValueExpr *Node) {

diff  --git a/clang/include/clang/AST/ComputeDependence.h 
b/clang/include/clang/AST/ComputeDependence.h
index f62611cb4c3cf..3360fd11ab1f7 100644
--- a/clang/include/clang/AST/ComputeDependence.h
+++ b/clang/include/clang/AST/ComputeDependence.h
@@ -79,7 +79,6 @@ class CXXUn

[clang] 95a4c0c - [clang] Reland parenthesized aggregate init patches

2023-01-12 Thread Alan Zhao via cfe-commits

Author: Alan Zhao
Date: 2023-01-12T09:58:15-08:00
New Revision: 95a4c0c83554c025ef709a6805e67233d0dedba0

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

LOG: [clang] Reland parenthesized aggregate init patches

This commit relands the patches for implementing P0960R3 and P1975R0,
which describe initializing aggregates via a parenthesized list.

The relanded commits are:

* 40c52159d3ee - P0960R3 and P1975R0: Allow initializing aggregates from
  a parenthesized list of values
* c77a91bb7ba7 - Remove overly restrictive aggregate paren init logic
* 32d7aae04fdb - Fix a clang crash on invalid code in C++20 mode

This patch also fixes a crash in the original implementation.
Previously, if the input tried to call an implicitly deleted copy or
move constructor of a union, we would then try to initialize the union
by initializing it's first element with a reference to a union. This
behavior is incorrect (we should fail to initialize) and if the type of
the first element has a constructor with a single template typename
parameter, then Clang will explode. This patch fixes that issue by
checking that constructor overload resolution did not result in a
deleted function before attempting parenthesized aggregate
initialization.

Additionally, this patch also includes D140159, which contains some
minor fixes made in response to code review comments in the original
implementation that were made after that patch was submitted.

Co-authored-by: Sheng 

Fixes #54040, Fixes #59675

Reviewed By: ilya-biryukov

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

Added: 
clang/test/CodeGen/paren-list-agg-init.cpp
clang/test/PCH/cxx_paren_init.cpp
clang/test/PCH/cxx_paren_init.h
clang/test/SemaCXX/paren-list-agg-init.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang-c/Index.h
clang/include/clang/AST/ASTNodeTraverser.h
clang/include/clang/AST/ComputeDependence.h
clang/include/clang/AST/Decl.h
clang/include/clang/AST/ExprCXX.h
clang/include/clang/AST/RecursiveASTVisitor.h
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Basic/StmtNodes.td
clang/include/clang/Sema/Initialization.h
clang/include/clang/Serialization/ASTBitCodes.h
clang/lib/AST/ComputeDependence.cpp
clang/lib/AST/Expr.cpp
clang/lib/AST/ExprCXX.cpp
clang/lib/AST/ExprClassification.cpp
clang/lib/AST/ExprConstant.cpp
clang/lib/AST/ItaniumMangle.cpp
clang/lib/AST/JSONNodeDumper.cpp
clang/lib/AST/StmtPrinter.cpp
clang/lib/AST/StmtProfile.cpp
clang/lib/AST/TextNodeDumper.cpp
clang/lib/CodeGen/CGExprAgg.cpp
clang/lib/Frontend/InitPreprocessor.cpp
clang/lib/Sema/SemaCast.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaExceptionSpec.cpp
clang/lib/Sema/SemaInit.cpp
clang/lib/Sema/TreeTransform.h
clang/lib/Serialization/ASTReaderStmt.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/lib/Serialization/ASTWriterStmt.cpp
clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
clang/test/CXX/temp/temp.decls/temp.variadic/p4.cpp
clang/test/Lexer/cxx-features.cpp
clang/test/SemaCXX/cxx2a-explicit-bool.cpp
clang/test/SemaCXX/recovery-expr-type.cpp
clang/tools/libclang/CIndex.cpp
clang/tools/libclang/CXCursor.cpp
clang/www/cxx_status.html

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index a9f1a1caf0bb7..ebc177ef1b1e7 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -740,6 +740,10 @@ C++20 Feature Support
 - Correctly handle access-checks in requires expression. Fixes `GH53364 
`_,
   `GH53334 `_.
 
+- Implemented `P0960R3: 
`_
+  and `P1975R0: 
`_,
+  which allows parenthesized aggregate-initialization.
+
 C++2b Feature Support
 ^
 

diff  --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h
index 5260085021928..fd758ddde085d 100644
--- a/clang/include/clang-c/Index.h
+++ b/clang/include/clang-c/Index.h
@@ -1531,7 +1531,13 @@ enum CXCursorKind {
*/
   CXCursor_RequiresExpr = 154,
 
-  CXCursor_LastExpr = CXCursor_RequiresExpr,
+  /**
+   * Expression that references a C++20 parenthesized list aggregate
+   * initializer.
+   */
+  CXCursor_CXXParenListInitExpr = 155,
+
+  CXCursor_LastExpr = CXCursor_CXXParenListInitExpr,
 
   /* Statements */
   CXCursor_FirstStmt = 200,

diff  --git a/clang/include/clang/AST/ASTNodeTraverser.h 
b/clang/include/clang/AST/ASTNodeTraverser.h
index 3089658305bfc..a2c57aab89ebc 100644
--

[clang] 4ad17d2 - Clean "./" from __FILE__ expansion.

2022-06-02 Thread Alan Zhao via cfe-commits

Author: Paul Pluzhnikov
Date: 2022-06-02T18:00:19-04:00
New Revision: 4ad17d2e96a382e5f595bab30920ba26762a6fa9

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

LOG: Clean "./" from __FILE__ expansion.

This is alternative to https://reviews.llvm.org/D121733
and helps with Clang header modules in which FILE
may expand to "./foo.h" or "foo.h" depending on whether the file was
included directly or not.

Only do this when UseTargetPathSeparator is true, as we are already
changing the path in that case.

Reviewed By: ayzhao

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

Added: 


Modified: 
clang/lib/Lex/PPMacroExpansion.cpp

Removed: 




diff  --git a/clang/lib/Lex/PPMacroExpansion.cpp 
b/clang/lib/Lex/PPMacroExpansion.cpp
index 9d1090be8e09..07ee07e20bb2 100644
--- a/clang/lib/Lex/PPMacroExpansion.cpp
+++ b/clang/lib/Lex/PPMacroExpansion.cpp
@@ -1895,9 +1895,9 @@ void 
Preprocessor::processPathForFileMacro(SmallVectorImpl &Path,
   LangOpts.remapPathPrefix(Path);
   if (LangOpts.UseTargetPathSeparator) {
 if (TI.getTriple().isOSWindows())
-  llvm::sys::path::make_preferred(
-  Path, llvm::sys::path::Style::windows_backslash);
+  llvm::sys::path::remove_dots(Path, false,
+   llvm::sys::path::Style::windows_backslash);
 else
-  llvm::sys::path::make_preferred(Path, llvm::sys::path::Style::posix);
+  llvm::sys::path::remove_dots(Path, false, llvm::sys::path::Style::posix);
   }
 }



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


[clang] fe0116a - [clang] Fix a crash when casting to an array type

2023-07-18 Thread Alan Zhao via cfe-commits

Author: Alan Zhao
Date: 2023-07-18T09:48:17-07:00
New Revision: fe0116aba833ee8597e2155d1e555c326acfaafc

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

LOG: [clang] Fix a crash when casting to an array type

In C++20, if Clang fails to perform constructor overload on a
RecordType, then Clang will try to perform parentesized aggregate
initialization. If that fails and the initialization was attempted as
part of a cast, then we should get the diagnostics from the failed
constructor overload attempt. However, we don't attempt constructor
overloading for arrays, so previously, if we try to diagnose an
overloaded cast for a parenthesized aggregate initialization of an
array, we crash. To fix this, we now exit tryDiagnoseOverloadedCast(...)
for failed parentesized list initialization if the destination type is
an array.

Fixes #63758

Reviewed By: aaron.ballman

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaCast.cpp
clang/test/SemaCXX/paren-list-agg-init.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index acc92b28ad9911..dd316a7a82e353 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -634,6 +634,8 @@ Bug Fixes in This Version
   that construct (`#62133 
_`).
 - Fix crash caused by PseudoObjectExprBitfields: NumSubExprs overflow.
   (`#63169 _`)
+- Fix crash when casting an object to an array type.
+  (`#63758 _`)
 
 Bug Fixes to Compiler Builtins
 ^^

diff  --git a/clang/lib/Sema/SemaCast.cpp b/clang/lib/Sema/SemaCast.cpp
index fc48f632e457ab..d65ecf52c52310 100644
--- a/clang/lib/Sema/SemaCast.cpp
+++ b/clang/lib/Sema/SemaCast.cpp
@@ -454,9 +454,27 @@ static bool tryDiagnoseOverloadedCast(Sema &S, CastType CT,
   switch (sequence.getFailureKind()) {
   default: return false;
 
+  case InitializationSequence::FK_ParenthesizedListInitFailed:
+// In C++20, if the underlying destination type is a RecordType, Clang
+// attempts to perform parentesized aggregate initialization if constructor
+// overload fails:
+//
+// C++20 [expr.static.cast]p4:
+//   An expression E can be explicitly converted to a type T...if overload
+//   resolution for a direct-initialization...would find at least one 
viable
+//   function ([over.match.viable]), or if T is an aggregate type having a
+//   first element X and there is an implicit conversion sequence from E to
+//   the type of X.
+//
+// If that fails, then we'll generate the diagnostics from the failed
+// previous constructor overload attempt. Array initialization, however, is
+// not done after attempting constructor overloading, so we exit as there
+// won't be a failed overload result.
+if (destType->isArrayType())
+  return false;
+break;
   case InitializationSequence::FK_ConstructorOverloadFailed:
   case InitializationSequence::FK_UserConversionOverloadFailed:
-  case InitializationSequence::FK_ParenthesizedListInitFailed:
 break;
   }
 

diff  --git a/clang/test/SemaCXX/paren-list-agg-init.cpp 
b/clang/test/SemaCXX/paren-list-agg-init.cpp
index 88d9b95c0e4be4..e2eec1779699ac 100644
--- a/clang/test/SemaCXX/paren-list-agg-init.cpp
+++ b/clang/test/SemaCXX/paren-list-agg-init.cpp
@@ -294,3 +294,8 @@ int test() {
 }
 
 }
+
+namespace gh63758 {
+  struct S {} s;
+  auto words = (char[])s; // expected-error {{C-style cast from 'struct S' to 
'char[]' is not allowed}}
+};



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


[clang] 7df3c71 - [clang] Fix 2 bugs with parenthesized aggregate initialization

2023-03-30 Thread Alan Zhao via cfe-commits

Author: Alan Zhao
Date: 2023-03-30T15:06:37-07:00
New Revision: 7df3c71b508b65284483225685f1ba19777f2bbb

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

LOG: [clang] Fix 2 bugs with parenthesized aggregate initialization

* Fix an issue where temporaries initialized via parenthesized aggregate
  initialization don't get destroyed.
* Fix an issue where aggregate initialization omits calls to class
  members' move constructors after a TreeTransform. This occurs because
  the CXXConstructExpr wrapping the call to the move constructor gets
  unboxed during a TreeTransform of the wrapping FunctionalCastExpr (as with a
  InitListExpr), but unlike InitListExpr, we dont reperform the
  InitializationSequence for the list's expressions to regenerate the
  CXXConstructExpr. This patch fixes this bug by treating
  CXXParenListInitExpr identically to InitListExpr in this regard.

Fixes #61145

Reviewed By: rsmith

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

Added: 


Modified: 
clang/lib/AST/Expr.cpp
clang/lib/Sema/SemaInit.cpp
clang/lib/Sema/TreeTransform.h
clang/test/CodeGen/paren-list-agg-init.cpp
clang/test/SemaCXX/paren-list-agg-init.cpp

Removed: 




diff  --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index f82587df0d70b..98b57966343be 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -1963,6 +1963,10 @@ Expr *ignoreImplicitSemaNodes(Expr *E) {
   if (auto *Full = dyn_cast(E))
 return Full->getSubExpr();
 
+  if (auto *CPLIE = dyn_cast(E);
+  CPLIE && CPLIE->getInitExprs().size() == 1)
+return CPLIE->getInitExprs()[0];
+
   return E;
 }
 } // namespace

diff  --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 46517c9dde06a..569024551d559 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -9180,6 +9180,8 @@ ExprResult InitializationSequence::Perform(Sema &S,
 /*VerifyOnly=*/false, &CurInit);
   if (CurInit.get() && ResultType)
 *ResultType = CurInit.get()->getType();
+  if (shouldBindAsTemporary(Entity))
+CurInit = S.MaybeBindToTemporary(CurInit.get());
   break;
 }
 }

diff  --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index 5de8cd9e3e343..94e1cec18053d 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -3173,6 +3173,13 @@ class TreeTransform {
   Expr *Sub,
   SourceLocation RParenLoc,
   bool ListInitialization) {
+// If Sub is a ParenListExpr, then Sub is the syntatic form of a
+// CXXParenListInitExpr. Pass its expanded arguments so that the
+// CXXParenListInitExpr can be rebuilt.
+if (auto *PLE = dyn_cast(Sub))
+  return getSema().BuildCXXTypeConstructExpr(
+  TInfo, LParenLoc, MultiExprArg(PLE->getExprs(), PLE->getNumExprs()),
+  RParenLoc, ListInitialization);
 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
MultiExprArg(&Sub, 1), 
RParenLoc,
ListInitialization);
@@ -3902,16 +3909,6 @@ class TreeTransform {
 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
   }
 
-  ExprResult RebuildCXXParenListInitExpr(ArrayRef Args, QualType T,
- unsigned NumUserSpecifiedExprs,
- SourceLocation InitLoc,
- SourceLocation LParenLoc,
- SourceLocation RParenLoc) {
-return CXXParenListInitExpr::Create(getSema().Context, Args, T,
-NumUserSpecifiedExprs, InitLoc,
-LParenLoc, RParenLoc);
-  }
-
   /// Build a new atomic operation expression.
   ///
   /// By default, performs semantic analysis to build the new expression.
@@ -14134,9 +14131,8 @@ 
TreeTransform::TransformCXXParenListInitExpr(CXXParenListInitExpr *E) {
  TransformedInits))
 return ExprError();
 
-  return getDerived().RebuildCXXParenListInitExpr(
-  TransformedInits, E->getType(), E->getUserSpecifiedInitExprs().size(),
-  E->getInitLoc(), E->getBeginLoc(), E->getEndLoc());
+  return getDerived().RebuildParenListExpr(E->getBeginLoc(), TransformedInits,
+   E->getEndLoc());
 }
 
 template

diff  --git a/clang/test/CodeGen/paren-list-agg-init.cpp 
b/clang/test/CodeGen/paren-list-agg-init.cpp
index a7534fb907d2b..a860196d8f500 100644
--- a/clang/test/CodeGen/paren-list-agg-init.cpp
+++ b/clang/

[clang] 1cf5188 - [clang] Fix crash when passing a braced-init list to a parentehsized aggregate init expression

2023-05-31 Thread Alan Zhao via cfe-commits

Author: Alan Zhao
Date: 2023-05-31T13:52:45-07:00
New Revision: 1cf5188c72902e85e85095d788f5dfa138c320f8

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

LOG: [clang] Fix crash when passing a braced-init list to a parentehsized 
aggregate init expression

The previous code incorrectly assumed that we would never call
warnBracedScalarInit(...) with a EK_ParenAggInitMember. This patch fixes
the bug by warning when a scalar member is initialized via a braced-init
list when performing a parentehsized aggregate initialization. This
behavior is consistent with parentehsized list aggregate initialization.

Fixes #63008

Reviewed By: shafik

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaInit.cpp
clang/test/SemaCXX/paren-list-agg-init.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b5814350a5f11..02736f2ee67fc 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -460,6 +460,9 @@ Bug Fixes in This Version
 - Fix crash when diagnosing default comparison method.
   (`#62791 `_) and
   (`#62102 `_).
+- Fix crash when passing a braced initializer list to a parentehsized aggregate
+  initialization expression.
+  (`#63008 `_).
 
 Bug Fixes to Compiler Builtins
 ^^

diff  --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index eaddba3e7c75d..f617cd021e594 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -1158,6 +1158,7 @@ static void warnBracedScalarInit(Sema &S, const 
InitializedEntity &Entity,
   case InitializedEntity::EK_Parameter_CF_Audited:
   case InitializedEntity::EK_TemplateParameter:
   case InitializedEntity::EK_Result:
+  case InitializedEntity::EK_ParenAggInitMember:
 // Extra braces here are suspicious.
 DiagID = diag::warn_braces_around_init;
 break;
@@ -1192,7 +1193,6 @@ static void warnBracedScalarInit(Sema &S, const 
InitializedEntity &Entity,
   case InitializedEntity::EK_LambdaToBlockConversionBlockElement:
   case InitializedEntity::EK_Binding:
   case InitializedEntity::EK_StmtExprResult:
-  case InitializedEntity::EK_ParenAggInitMember:
 llvm_unreachable("unexpected braced scalar init");
   }
 

diff  --git a/clang/test/SemaCXX/paren-list-agg-init.cpp 
b/clang/test/SemaCXX/paren-list-agg-init.cpp
index 7bdf49b8fd0c1..042ce3b3ddce2 100644
--- a/clang/test/SemaCXX/paren-list-agg-init.cpp
+++ b/clang/test/SemaCXX/paren-list-agg-init.cpp
@@ -266,3 +266,9 @@ O o2(0, 0); // no-error
 O o3(0);
 // expected-error@-1 {{reference member of type 'int &&' uninitialized}}
 }
+
+namespace gh63008 {
+auto a = new A('a', {1.1});
+// expected-warning@-1 {{braces around scalar init}}
+// beforecxx20-warning@-2 {{aggregate initialization of type 'A' from a 
parenthesized list of values is a C++20 extension}}
+}



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


[clang] d1d35f0 - [clang] Fix initializer_list matching failures with modules

2023-05-09 Thread Alan Zhao via cfe-commits

Author: Alan Zhao
Date: 2023-05-09T10:31:43-07:00
New Revision: d1d35f04c6cb2e3d5b0fbc6101d5425a33f8fc63

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

LOG: [clang] Fix initializer_list matching failures with modules

Previously, if a class with a defined public virtual destructor is
declared before including  and initializer_list is
provided via a Clang module, then overload resolution would fail for
std::initializer_list. This is because when Clang sees the virtual
destructor, Clang creates an implicit NamespaceDecl for std to
implicitly declare a std::bad_alloc. That NamespaceDecl is not added to
the translation unit's lookup table, so when the module containing
std::initializer_list is imported later, that module's std NamespaceDecl
can't find the previous std NamespaceDecl during redeclaration lookup,
causing overload resolution to fail.

To fix this, implicitly created std NamespaceDecls are now added to the
lookup map. At the same time, their IdentifierNamespace members are
cleared to prevent regular name lookups from finding it.

Fixes 60929

Reviewed By: ChuanqiXu, #clang-language-wg, inclyc

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

Added: 
clang/test/Modules/match_initializer_list.cpp

Modified: 
clang/include/clang/AST/DeclBase.h
clang/lib/Sema/SemaDeclCXX.cpp

Removed: 




diff  --git a/clang/include/clang/AST/DeclBase.h 
b/clang/include/clang/AST/DeclBase.h
index e86eadab0a8a4..be76d1648b9ac 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -1172,6 +1172,12 @@ class alignas(8) Decl {
 }
   }
 
+  /// Clears the namespace of this declaration.
+  ///
+  /// This is useful if we want this declaration to be available for
+  /// redeclaration lookup but otherwise hidden for ordinary name lookups.
+  void clearIdentifierNamespace() { IdentifierNamespace = 0; }
+
   enum FriendObjectKind {
 FOK_None,  ///< Not a friend object.
 FOK_Declared,  ///< A friend of a previously-declared entity.

diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 4efa1b408607d..e68afaa61ef1c 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -11567,6 +11567,10 @@ NamespaceDecl *Sema::getOrCreateStdNamespace() {
 &PP.getIdentifierTable().get("std"),
 /*PrevDecl=*/nullptr, /*Nested=*/false);
 getStdNamespace()->setImplicit(true);
+// We want the created NamespaceDecl to be available for redeclaration
+// lookups, but not for regular name lookups.
+Context.getTranslationUnitDecl()->addDecl(getStdNamespace());
+getStdNamespace()->clearIdentifierNamespace();
   }
 
   return getStdNamespace();

diff  --git a/clang/test/Modules/match_initializer_list.cpp 
b/clang/test/Modules/match_initializer_list.cpp
new file mode 100644
index 0..31e2b015a9d05
--- /dev/null
+++ b/clang/test/Modules/match_initializer_list.cpp
@@ -0,0 +1,19 @@
+// RUN: rm -rf %t
+//
+// RUN: %clang_cc1 -x c++ -fmodules -fmodules-cache-path=%t \
+// RUN: -I %S/Inputs/initializer_list \
+// RUN: -fmodule-map-file=%S/Inputs/initializer_list/direct.modulemap \
+// RUN: %s -verify
+
+// expected-no-diagnostics
+
+class C {
+  public:
+  virtual ~C() {}
+};
+
+#include "Inputs/initializer_list/direct.h"
+
+void takesInitList(std::initializer_list);
+
+void passesInitList() { takesInitList({0}); }



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


[clang] 7417e9d - [clang] Fix a crash with parenthesized aggregate initialization and base classes

2023-04-27 Thread Alan Zhao via cfe-commits

Author: Alan Zhao
Date: 2023-04-27T10:43:16-07:00
New Revision: 7417e9d75c9af7dd0d3dad12eebdee84b10b56d7

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

LOG: [clang] Fix a crash with parenthesized aggregate initialization and base 
classes

When calling InitializeBase(...), TryOrBuidlParenListInit(...) needs to
pass in the parent entity; otherwise, we erroneously try to cast
CurContext to a CXXConstructorDecl[0], which can't be done since we're
performing aggregate initialization, not constructor initialization.

Field initialization is not affected, but this patch still adds some
tests for it.

Fixes 62296

[0]: 
https://github.com/llvm/llvm-project/blob/33d6bd1c667456f7f4a9d338a7996a30a3af50a3/clang/lib/Sema/SemaAccess.cpp#L1696

Reviewed By: aaron.ballman

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaInit.cpp
clang/test/SemaCXX/paren-list-agg-init.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index aff9ce378253..85eb445a8739 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -331,6 +331,9 @@ Bug Fixes in This Version
   constructor declaration.
   (`#62361 `_)
   (`#62362 `_)
+- Fix crash when attempting to perform parenthesized initialization of an
+  aggregate with a base class with only non-public constructors.
+  (`#62296 `_)
 
 Bug Fixes to Compiler Builtins
 ^^

diff  --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 243c3c1c9a4d..c218470d37ae 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -5449,8 +5449,9 @@ static void TryOrBuildParenListInitialization(
   } else if (auto *RT = Entity.getType()->getAs()) {
 const CXXRecordDecl *RD = cast(RT->getDecl());
 
-auto BaseRange = map_range(RD->bases(), [&S](auto &base) {
-  return InitializedEntity::InitializeBase(S.getASTContext(), &base, 
false);
+auto BaseRange = map_range(RD->bases(), [&](auto &base) {
+  return InitializedEntity::InitializeBase(S.getASTContext(), &base, false,
+   &Entity);
 });
 auto FieldRange = map_range(RD->fields(), [](auto *field) {
   return InitializedEntity::InitializeMember(field);

diff  --git a/clang/test/SemaCXX/paren-list-agg-init.cpp 
b/clang/test/SemaCXX/paren-list-agg-init.cpp
index a5f39ff6c477..c9d73327025c 100644
--- a/clang/test/SemaCXX/paren-list-agg-init.cpp
+++ b/clang/test/SemaCXX/paren-list-agg-init.cpp
@@ -200,3 +200,26 @@ void bar() {
   // expected-error@-1 {{call to implicitly-deleted copy constructor of 'V'}}
 }
 }
+
+namespace gh62296 {
+struct L {
+protected:
+  L(int);
+  // expected-note@-1 2{{declared protected here}}
+};
+
+struct M : L {};
+
+struct N {
+  L l;
+};
+
+M m(42);
+// expected-error@-1 {{base class 'L' has protected constructor}}
+// beforecxx20-warning@-2 {{aggregate initialization of type 'M' from a 
parenthesized list of values is a C++20 extension}}
+
+N n(43);
+// expected-error@-1 {{field of type 'L' has protected constructor}}
+// beforecxx20-warning@-2 {{aggregate initialization of type 'N' from a 
parenthesized list of values is a C++20 extension}}
+
+}



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


[clang] 3e22eb3 - Fix spacing in ReleaseNotes.rst link

2023-04-27 Thread Alan Zhao via cfe-commits

Author: Alan Zhao
Date: 2023-04-27T11:41:21-07:00
New Revision: 3e22eb36b6ffd60608a0e70401b021738c1c4fe8

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

LOG: Fix spacing in ReleaseNotes.rst link

Added: 


Modified: 
clang/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index a382c5e64ece..8082e9d9f323 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -335,7 +335,7 @@ Bug Fixes in This Version
   (`#62362 `_)
 - Fix crash when attempting to perform parenthesized initialization of an
   aggregate with a base class with only non-public constructors.
-  (`#62296 `_)
+  (`#62296 `_)
 
 Bug Fixes to Compiler Builtins
 ^^



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


[clang] da0089c - [clang] Fix default initializers being ignored when initializing templated aggregate types

2023-05-01 Thread Alan Zhao via cfe-commits

Author: Alan Zhao
Date: 2023-05-01T09:27:52-07:00
New Revision: da0089c99ba1507b876cf3d2a205ba108aad65ff

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

LOG: [clang] Fix default initializers being ignored when initializing templated 
aggregate types

Previously, when checking whether an in-class initializer exists when
performing parenthesized aggregate initialization, Clang checks that the
output of FieldDecl::getInClassInitializer() is non-null. This is
incorrect; if the field is part of a templated type, then
getInClassInitializer() will return nullptr if we haven't called
Sem::BuildCXXDefaultInitExpr(...) before, even if
FieldDecl::hasInClassInitializer() returns true. The end result is that
Clang incorrectly ignores the in class initializer and
value-initializes the field. The fix therefore is to instead call
FieldDecl::hasInClassInitializer(), which is what we do for braced init
lists [0].

Before this patch, Clang does correctly recognize the in-class field
initializer in certain cases. This is Sema::BuildCXXDefaultInitExpr(...)
populates the in class initializer of the corresponding FieldDecl
object. Therefore, if that method was previously called with the same
FieldDecl object, as can happen with a decltype(...) or a braced list
initialization, FieldDecl::getInClassInitializer() will return a
non-null expression, and the field becomes properly initialized.

Fixes 62266

[0]: 
https://github.com/llvm/llvm-project/blob/be5f35e24f4c15caf3c4aeccddc54c52560c28a0/clang/lib/Sema/SemaInit.cpp#L685

Reviewed By: shafik

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

Added: 


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

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6cc736205dd02..eaabe08599520 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -373,6 +373,9 @@ Bug Fixes to C++ Support
 - Fix bug in the computation of the ``__has_unique_object_representations``
   builtin for types with unnamed bitfields.
   (`#61336 `_)
+- Fix default member initializers sometimes being ignored when performing
+  parenthesized aggregate initialization of templated types.
+  (`#62266 `_)
 
 Bug Fixes to AST Handling
 ^

diff  --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index c218470d37ae6..55ef72de9b24e 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -5377,14 +5377,16 @@ static void TryOrBuildParenListInitialization(
   //   The remaining elements are initialized with their default member
   //   initializers, if any
   auto *FD = cast(SubEntity.getDecl());
-  if (Expr *ICE = FD->getInClassInitializer(); ICE && !VerifyOnly) {
-ExprResult DIE = S.BuildCXXDefaultInitExpr(FD->getLocation(), FD);
-if (DIE.isInvalid())
-  return false;
-S.checkInitializerLifetime(SubEntity, DIE.get());
-InitExprs.push_back(DIE.get());
+  if (FD->hasInClassInitializer()) {
+if (!VerifyOnly) {
+  ExprResult DIE = S.BuildCXXDefaultInitExpr(FD->getLocation(), 
FD);
+  if (DIE.isInvalid())
+return false;
+  S.checkInitializerLifetime(SubEntity, DIE.get());
+  InitExprs.push_back(DIE.get());
+}
 continue;
-  };
+  }
 }
 // Remaining class elements without default member initializers and
 // array elements are value initialized:

diff  --git a/clang/test/CodeGen/paren-list-agg-init.cpp 
b/clang/test/CodeGen/paren-list-agg-init.cpp
index a860196d8f500..7e06a466b6c0a 100644
--- a/clang/test/CodeGen/paren-list-agg-init.cpp
+++ b/clang/test/CodeGen/paren-list-agg-init.cpp
@@ -90,6 +90,15 @@ namespace gh61145 {
   };
 }
 
+namespace gh62266 {
+  // CHECK-DAG: [[STRUCT_H:%.*H.*]] = type { i32, i32 }
+  template 
+  struct H {
+int i;
+int j = J;
+  };
+}
+
 // CHECK-DAG: [[A1:@.*a1.*]] = internal constant [[STRUCT_A]] { i8 3, double 
2.00e+00 }, align 8
 constexpr A a1(3.1, 2.0);
 // CHECK-DAG: [[A2:@.*a2.*]] = internal constant [[STRUCT_A]] { i8 99, double 
0.00e+00 }, align 8
@@ -421,3 +430,17 @@ namespace gh61145 {
 make2<0>();
   }
 }
+
+namespace gh62266 {
+  // CHECK: define {{.*}} void {{.*foo20.*}}
+  // CHECK-NEXT: entry:
+  // CHECK-NEXT: [[H:%.*h.*]] = alloca [[STRUCT_H]], align 4
+  // CHECK-NEXT: [[I:%.*i.*]] = getelementptr inbounds [[STRUCT_H]], ptr 
[[H]], i32 0, i32 0
+  // CHECK-NEXT: store i32 1, ptr [[I]], align 4
+  // CHEC

[clang] 9b4faa1 - [clang] Fix overly aggressive lifetime checks for parenthesized aggregate initialization

2023-05-01 Thread Alan Zhao via cfe-commits

Author: Alan Zhao
Date: 2023-05-01T10:02:15-07:00
New Revision: 9b4faa11c68be4b45ddf29acd575bb52a3c2fad7

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

LOG: [clang] Fix overly aggressive lifetime checks for parenthesized aggregate 
initialization

Before this patch, initialized class members would have the LifetimeKind
LK_MemInitializer, which does not allow for binding a temporary to a
reference. Binding to a temporary however is allowed in parenthesized
aggregate initialization, even if it leads to a dangling reference. To
fix this, we create a new EntityKind, EK_ParenAggInitMember, which has
LifetimeKind LK_FullExpression.

This patch does *not* attempt to diagnose dangling references as a
result of using this feature.

This patch also refactors TryOrBuildParenListInitialization(...) to
accomodate creating different InitializedEntity objects.

Fixes #61567

[0]: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p0960r3.html

Reviewed By: shafik

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Initialization.h
clang/lib/Sema/SemaAccess.cpp
clang/lib/Sema/SemaInit.cpp
clang/test/CodeGen/paren-list-agg-init.cpp
clang/test/SemaCXX/paren-list-agg-init.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index eaabe08599520..ec0dc0adc58b0 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -373,9 +373,15 @@ Bug Fixes to C++ Support
 - Fix bug in the computation of the ``__has_unique_object_representations``
   builtin for types with unnamed bitfields.
   (`#61336 `_)
+<<< HEAD
 - Fix default member initializers sometimes being ignored when performing
   parenthesized aggregate initialization of templated types.
   (`#62266 `_)
+===
+- Fix overly aggressive lifetime checks for parenthesized aggregate
+  initialization.
+  (`#61567 `_)
+>>> c7422b289522 ([clang] Fix overly aggressive lifetime checks for 
parenthesized aggregate initialization)
 
 Bug Fixes to AST Handling
 ^

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 7d0ee502eabfc..17585752edf8e 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2126,7 +2126,8 @@ def err_init_conversion_failed : Error<
   "exception object|a member subobject|an array element|a new value|a value|a "
   "base class|a constructor delegation|a vector element|a block element|a "
   "block element|a complex element|a lambda capture|a compound literal "
-  "initializer|a related result|a parameter of CF audited function}0 "
+  "initializer|a related result|a parameter of CF audited function|a "
+  "structured binding|a member subobject}0 "
   "%
diff {of type $ with an %select{rvalue|lvalue}2 of type $|"
   "with an %select{rvalue|lvalue}2 of incompatible type}1,3"
   "%select{|: 
diff erent classes%
diff { ($ vs $)|}5,6"

diff  --git a/clang/include/clang/Sema/Initialization.h 
b/clang/include/clang/Sema/Initialization.h
index fcfb56f9731ef..2072cd8d1c3ef 100644
--- a/clang/include/clang/Sema/Initialization.h
+++ b/clang/include/clang/Sema/Initialization.h
@@ -123,6 +123,10 @@ class alignas(8) InitializedEntity {
 /// decomposition declaration.
 EK_Binding,
 
+/// The entity being initialized is a non-static data member subobject of 
an
+/// object initialized via parenthesized aggregate initialization.
+EK_ParenAggInitMember,
+
 // Note: err_init_conversion_failed in DiagnosticSemaKinds.td uses this
 // enum as an index for its first %select.  When modifying this list,
 // that diagnostic text needs to be updated as well.
@@ -227,8 +231,10 @@ class alignas(8) InitializedEntity {
 
   /// Create the initialization entity for a member subobject.
   InitializedEntity(FieldDecl *Member, const InitializedEntity *Parent,
-bool Implicit, bool DefaultMemberInit)
-  : Kind(EK_Member), Parent(Parent), Type(Member->getType()),
+bool Implicit, bool DefaultMemberInit,
+bool IsParenAggInit = false)
+  : Kind(IsParenAggInit ? EK_ParenAggInitMember : EK_Member),
+Parent(Parent), Type(Member->getType()),
 Variable{Member, Implicit, DefaultMemberInit} {}
 
   /// Create the initialization entity for an array element.
@@ -388,6 +394,14 @@ class alignas(8) InitializedEntity {
 return InitializedEnti

[clang] f762798 - Fix ReleaseNotes.rst unresolved merge conflict

2023-05-01 Thread Alan Zhao via cfe-commits

Author: Alan Zhao
Date: 2023-05-01T10:26:15-07:00
New Revision: f762798599171efca03964f4371cc8104d2392f9

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

LOG: Fix ReleaseNotes.rst unresolved merge conflict

Added: 


Modified: 
clang/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ec0dc0adc58b..a3ee06ba1c22 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -373,15 +373,12 @@ Bug Fixes to C++ Support
 - Fix bug in the computation of the ``__has_unique_object_representations``
   builtin for types with unnamed bitfields.
   (`#61336 `_)
-<<< HEAD
 - Fix default member initializers sometimes being ignored when performing
   parenthesized aggregate initialization of templated types.
   (`#62266 `_)
-===
 - Fix overly aggressive lifetime checks for parenthesized aggregate
   initialization.
   (`#61567 `_)
->>> c7422b289522 ([clang] Fix overly aggressive lifetime checks for 
parenthesized aggregate initialization)
 
 Bug Fixes to AST Handling
 ^



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


[clang] 40c5215 - [clang][C++20] P0960R3 and P1975R0: Allow initializing aggregates from a parenthesized list of values

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

Author: Alan Zhao
Date: 2022-12-14T07:54:15-08:00
New Revision: 40c52159d3ee337dbed14e4c73b5616ea354c337

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

LOG: [clang][C++20] P0960R3 and P1975R0: Allow initializing aggregates from a 
parenthesized list of values

This patch implements P0960R3, which allows initialization of aggregates
via parentheses.

As an example:

```
struct S { int i, j; };
S s1(1, 1);

int arr1[2](1, 2);
```

This patch also implements P1975R0, which fixes the wording of P0960R3
for single-argument parenthesized lists so that statements like the
following are allowed:

```
S s2(1);
S s3 = static_cast(1);
S s4 = (S)1;

int (&&arr2)[] = static_cast(1);
int (&&arr3)[2] = static_cast(1);
```

This patch was originally authored by @0x59616e and completed by
@ayzhao.

Fixes #54040, Fixes #54041

Co-authored-by: Sheng 

Full write up : 
https://discourse.llvm.org/t/c-20-rfc-suggestion-desired-regarding-the-implementation-of-p0960r3/63744

Reviewed By: ilya-biryukov

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

Added: 
clang/test/CodeGen/paren-list-agg-init.cpp
clang/test/PCH/cxx_paren_init.cpp
clang/test/PCH/cxx_paren_init.h
clang/test/SemaCXX/paren-list-agg-init.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang-c/Index.h
clang/include/clang/AST/ASTNodeTraverser.h
clang/include/clang/AST/ComputeDependence.h
clang/include/clang/AST/Decl.h
clang/include/clang/AST/ExprCXX.h
clang/include/clang/AST/RecursiveASTVisitor.h
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Basic/StmtNodes.td
clang/include/clang/Sema/Initialization.h
clang/include/clang/Serialization/ASTBitCodes.h
clang/lib/AST/ComputeDependence.cpp
clang/lib/AST/Expr.cpp
clang/lib/AST/ExprCXX.cpp
clang/lib/AST/ExprClassification.cpp
clang/lib/AST/ExprConstant.cpp
clang/lib/AST/ItaniumMangle.cpp
clang/lib/AST/JSONNodeDumper.cpp
clang/lib/AST/StmtPrinter.cpp
clang/lib/AST/StmtProfile.cpp
clang/lib/AST/TextNodeDumper.cpp
clang/lib/CodeGen/CGExprAgg.cpp
clang/lib/Frontend/InitPreprocessor.cpp
clang/lib/Sema/SemaCast.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaExceptionSpec.cpp
clang/lib/Sema/SemaInit.cpp
clang/lib/Sema/TreeTransform.h
clang/lib/Serialization/ASTReaderStmt.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/lib/Serialization/ASTWriterStmt.cpp
clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
clang/test/CXX/temp/temp.decls/temp.variadic/p4.cpp
clang/test/Lexer/cxx-features.cpp
clang/test/SemaCXX/cxx2a-explicit-bool.cpp
clang/tools/libclang/CIndex.cpp
clang/tools/libclang/CXCursor.cpp
clang/www/cxx_status.html

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index cad59b0ce5def..ae6a52f572092 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -697,6 +697,10 @@ C++20 Feature Support
   (useful specially for constrained members). Fixes `GH50886 
`_.
 - Implemented CWG2635 as a Defect Report, which prohibits structured bindings 
from being constrained.
 
+- Implemented `P0960R3: 
`_
+  and `P1975R0: 
`_,
+  which allows parenthesized aggregate-initialization.
+
 C++2b Feature Support
 ^
 

diff  --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h
index 5260085021928..fd758ddde085d 100644
--- a/clang/include/clang-c/Index.h
+++ b/clang/include/clang-c/Index.h
@@ -1531,7 +1531,13 @@ enum CXCursorKind {
*/
   CXCursor_RequiresExpr = 154,
 
-  CXCursor_LastExpr = CXCursor_RequiresExpr,
+  /**
+   * Expression that references a C++20 parenthesized list aggregate
+   * initializer.
+   */
+  CXCursor_CXXParenListInitExpr = 155,
+
+  CXCursor_LastExpr = CXCursor_CXXParenListInitExpr,
 
   /* Statements */
   CXCursor_FirstStmt = 200,

diff  --git a/clang/include/clang/AST/ASTNodeTraverser.h 
b/clang/include/clang/AST/ASTNodeTraverser.h
index 8f19cf77c9fef..7ad5e460432c0 100644
--- a/clang/include/clang/AST/ASTNodeTraverser.h
+++ b/clang/include/clang/AST/ASTNodeTraverser.h
@@ -710,6 +710,12 @@ class ASTNodeTraverser
 }
   }
 
+  void VisitCXXParenListInitExpr(const CXXParenListInitExpr *PLIE) {
+if (auto *Filler = PLIE->getArrayFiller()) {
+  Visit(Filler, "array_filler");
+}
+  }
+
   void VisitBlockExpr(const BlockExpr *Node) { Visit(Node->getBlockDecl()); }
 
   void VisitOpaqueValueExpr(const OpaqueValueExpr *Node) {

diff  --git a/clang/include/clang/AST/ComputeDependence.h 
b/clang/includ

[clang] [lldb] [clang][AST] fix ast-print of extern with >=2 declarators, fixed (PR #93913)

2024-07-01 Thread Alan Zhao via cfe-commits

alanzhao1 wrote:

Chrome's Windows debug builds also saw crashes due to this commit: 
https://crbug.com/350541784

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


[clang] [Analyzer][CFG] Correctly handle rebuilt default arg and default init expression (PR #91879)

2024-05-28 Thread Alan Zhao via cfe-commits

alanzhao1 wrote:

FYI this patch messes up some diagnostics with `-Wunreachable-code`: 
https://godbolt.org/z/6TEdrx55d

If the unreachable code is a constructor with a default parameter that is a 
builtin function, clang incorrectly highlights the call to the builtin instead 
of the call to the constructor.

There's a similar issue if instead of a builtin the default parameter is the 
return value of another function which itself has default parameter that is a 
builtin: https://godbolt.org/z/ErarnbGbY

This was originally observed in Chrome - see https://crbug.com/343231820.



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


[clang] [clang] Emit constraint intrinsics for arc and hyperbolic trig clang builtins (PR #98949)

2024-07-30 Thread Alan Zhao via cfe-commits

alanzhao1 wrote:

We (Chrome) are seeing linker failures on our x86 Windows builds due to this 
PR: https://crbug.com/355455678

```
[12702/86218] LINK glmark2_wgl.exe glmark2_wgl.exe.pdb
..\..\third_party\llvm-build\Release+Asserts\bin\lld-link.exe 
/OUT:./glmark2_wgl.exe /nologo 
-libpath:..\..\third_party\llvm-build\Release+Asserts\lib\clang\20\lib\windows 
/winsysroot:../../third_party/depot_tools/win_toolchain/vs_files/7393122652 
/MACHINE:X86 /PDB:./glmark2_wgl.exe.pdb @./glmark2_wgl.exe.rsp
lld-link: error: undefined symbol: _asinf
>>> referenced by 
>>> .\..\..\third_party\angle\third_party\glmark2\src\src\model.cpp:266
>>>   
>>> obj/third_party/angle/third_party/glmark2/glmark2_common_gl/model.obj:(public:
>>>  void __thiscall Model::calculate_texcoords(void))
>>> referenced by 
>>> .\..\..\third_party\angle\third_party\glmark2\src\src\model.cpp:267
>>>   
>>> obj/third_party/angle/third_party/glmark2/glmark2_common_gl/model.obj:(public:
>>>  void __thiscall Model::calculate_texcoords(void))

lld-link: error: undefined symbol: _atanf
>>> referenced by 
>>> .\..\..\third_party\angle\third_party\glmark2\src\src\scene-build.cpp:179
>>>   
>>> obj/third_party/angle/third_party/glmark2/glmark2_common_gl/scene-build.obj:(public:
>>>  virtual bool __thiscall SceneBuild::setup(void))
>>> referenced by 
>>> .\..\..\third_party\angle\third_party\glmark2\src\src\scene-refract.cpp:382
>>>   
>>> obj/third_party/angle/third_party/glmark2/glmark2_common_gl/scene-refract.obj:(public:
>>>  bool __thiscall RefractPrivate::setup(class std::__Cr::map>> std::__Cr::basic_string, class 
>>> std::__Cr::allocator>, struct Scene::Option, struct 
>>> std::__Cr::less>> std::__Cr::char_traits, class std::__Cr::allocator>>, class 
>>> std::__Cr::allocator>> std::__Cr::basic_string, class 
>>> std::__Cr::allocator> const, struct Scene::Option>>> &))
>>> referenced by 
>>> .\..\..\third_party\angle\third_party\glmark2\src\src\scene-shading.cpp:250
>>>   
>>> obj/third_party/angle/third_party/glmark2/glmark2_common_gl/scene-shading.obj:(public:
>>>  virtual bool __thiscall SceneShading::setup(void))
>>> referenced 2 more times
exit=1
error: 1 steps failed
```

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


[clang] [clang] Emit constraint intrinsics for arc and hyperbolic trig clang builtins (PR #98949)

2024-07-30 Thread Alan Zhao via cfe-commits

alanzhao1 wrote:

> @alanzhao1 @efriedma-quic It should be fixed now by #101268 if you role the 
> clang build to latest.

Confirmed. Thanks!

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


[clang] [clang] Emit bad shift warnings (PR #70307)

2024-07-18 Thread Alan Zhao via cfe-commits

alanzhao1 wrote:

> > @alanzhao1 do you think it's reasonable for the workaround to only apply to 
> > code in system headers, or does the NDK get included as regular headers 
> > generally?
> 
> Having it only apply to system headers should be OK - in our case, chrome 
> imports these headers as part of a `--sysroot`, which IIRC treats warnings 
> the same way as `-isystem`
> 
> > Do you need us to revert the changes while we resolve this?
> 
> If you can revert while working on a solution, that would be helpful.

We (Chrome) no longer need a revert - we patched the NDK locally.

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


[clang] [clang] Emit bad shift warnings (PR #70307)

2024-07-12 Thread Alan Zhao via cfe-commits

alanzhao1 wrote:

> @alanzhao1 do you think it's reasonable for the workaround to only apply to 
> code in system headers, or does the NDK get included as regular headers 
> generally? 

Having it only apply to system headers should be OK - in our case, chrome 
imports these headers as part of a `--sysroot`, which IIRC treats warnings the 
same way as `-isystem`

>  Do you need us to revert the changes while we resolve this?

If you can revert while working on a solution, that would be helpful.

> > @budimirarandjelovicsyrmia, can you please add a workaround so that the NDK 
> > code can continue to compile?
> 
> I will investigate this.

FYI I noticed that gcc can compile this with `-fpermissive`

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


[clang] [llvm] [X86][AMX] Support AMX-AVX512 (PR #114070)

2024-11-08 Thread Alan Zhao via cfe-commits

alanzhao1 wrote:

> FYI this is causing Chrome X86 MacOS builds to fail due to `error: unknown 
> type name '__m512bh'`: https://crbug.com/378111077

As I mentioned in https://crbug.com/378111077#comment3, the issue is that we 
pull in avx512bf16intrin.h because `__SCE__` is not defined, but `__SSE2__` is 
also not defined, so we don't pull in the `typedef` for `__m512bh` (since 
they're guarded by macros that look for `__SSE2__`) and so on. We then pull in 
amxavx512intrin.h which was introduced in this PR which then fails to compile 
because we don't have the `typedef`s.

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


[clang] [llvm] [X86][AMX] Support AMX-AVX512 (PR #114070)

2024-11-08 Thread Alan Zhao via cfe-commits

alanzhao1 wrote:

FYI this is causing Chrome X86 MacOS builds to fail due to `error: unknown type 
name '__m512bh'`: https://crbug.com/378111077

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


[clang] [Clang] skip default argument instantiation for non-defining friend declarations without specialization info to meet [dcl.fct.default] p4 (PR #113777)

2024-11-07 Thread Alan Zhao via cfe-commits

alanzhao1 wrote:

FYI this is causing Clang to crash with Chrome: https://crbug.com/377956048

I'm currently working on getting a reduced repro with CReduce.

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


[clang] [Clang] skip default argument instantiation for non-defining friend declarations without specialization info to meet [dcl.fct.default] p4 (PR #113777)

2024-11-07 Thread Alan Zhao via cfe-commits

alanzhao1 wrote:

Based on the [patch reversion 
policy](https://llvm.org/docs/DeveloperPolicy.html#patch-reversion-policy), I 
think reverting is the right thing to do.

(I'm working on the reduced repro, but creduce is _really_ slow. In the 
meantime, I attached the unreduced files). 

[unreduced.tar.gz](https://github.com/user-attachments/files/17671006/unreduced.tar.gz)

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


[clang] [Clang] skip default argument instantiation for non-defining friend declarations without specialization info to meet [dcl.fct.default] p4 (PR #113777)

2024-11-07 Thread Alan Zhao via cfe-commits

alanzhao1 wrote:

For posterity, here's the entire stacktrace I got:

```
/usr/local/google/home/ayzhao/src/llvm-project/build/bin/clang++ -MMD -MF 
obj/third_party/dawn/src/dawn/tests/dawn_unittests/CacheRequestTests.o.d 
-DUSE_UDEV -DUSE_AURA=1 -DUSE_GLIB=1 -DUSE_OZONE=1 -D__STDC_CONSTANT_MACROS 
-D__STDC_FORMAT_MACROS -D_FORTIFY_SOURCE=2 -D_FILE_OFFSET_BITS=64 
-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_GNU_SOURCE 
-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_EXTENSIVE 
-D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS 
-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS 
-DCR_LIBCXX_REVISION=8e31ad42561900383e10dbefc1d3e8f38cedfbe9 
-DTMP_REBUILD_HACK -DCR_SYSROOT_KEY=20230611T210420Z-2 -DNDEBUG -DNVALGRIND 
-DDYNAMIC_ANNOTATIONS_ENABLED=0 -DDAWN_ABORT_ON_ASSERT 
-DDAWN_ENABLE_BACKEND_NULL -DDAWN_ENABLE_BACKEND_OPENGL 
-DDAWN_ENABLE_BACKEND_DESKTOP_GL -DDAWN_ENABLE_BACKEND_OPENGLES 
-DDAWN_ENABLE_BACKEND_VULKAN -DDAWN_USE_X11 -DTINT_BUILD_SPV_READER=0 
-DTINT_BUILD_SPV_WRITER=1 -DTINT_BUILD_WGSL_READER=1 -DTINT_BUILD_WGSL_WRITER=1 
-DTINT_BUILD_MSL_WRITER=1 -DTINT_BUILD_HLSL_WRITER=1 -DTINT_BUILD_GLSL_WRITER=1 
-DTINT_BUILD_GLSL_VALIDATOR=1 -DTINT_BUILD_SYNTAX_TREE_WRITER=0 
-DTINT_BUILD_IR_BINARY=1 -DTINT_BUILD_IR_FUZZER=0 -DTINT_BUILD_IS_WIN=0 
-DTINT_BUILD_IS_MAC=0 -DTINT_BUILD_IS_LINUX=1 
-DGLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_2_56 
-DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_56 -DBENCHMARK_STATIC_DEFINE 
-DCR_CXX_INCLUDE=\"third_party/rust/chromium_crates_io/vendor/cxx-1.0.129/include/cxx.h\"
 -DU_USING_ICU_NAMESPACE=0 -DU_ENABLE_DYLOAD=0 -DUSE_CHROMIUM_ICU=1 
-DU_ENABLE_TRACING=1 -DU_ENABLE_RESOURCE_TRACING=0 -DU_STATIC_IMPLEMENTATION 
-DICU_UTIL_DATA_IMPL=ICU_UTIL_DATA_FILE -DGTEST_API_= -DGTEST_HAS_POSIX_RE=0 
-DGTEST_LANG_CXX11=1 -DGTEST_HAS_TR1_TUPLE=0 -DGTEST_HAS_ABSL 
-DGTEST_NO_ABSL_FLAGS -DUNIT_TEST -DVK_USE_PLATFORM_XCB_KHR 
-DVK_USE_PLATFORM_WAYLAND_KHR -I../.. -Igen 
-I../../buildtools/third_party/libc++ -Igen/third_party/dawn/src 
-I../../third_party/dawn/src -I../../third_party/dawn 
-I../../third_party/dawn/include -Igen/third_party/dawn 
-I../../third_party/perfetto/include -Igen/third_party/perfetto/build_config 
-Igen/third_party/perfetto -I../../third_party/google_benchmark/src/include 
-Igen/third_party/dawn/include -I../../base/allocator/partition_allocator/src 
-Igen/base/allocator/partition_allocator/src -I../../third_party/abseil-cpp 
-I../../third_party/boringssl/src/include -I../../third_party/protobuf/src 
-I../../third_party/ced/src -I../../third_party/icu/source/common 
-I../../third_party/icu/source/i18n -I../../third_party/googletest/custom 
-I../../third_party/googletest/src/googlemock/include 
-I../../third_party/googletest/src/googletest/include 
-I../../third_party/re2/src -I../../third_party/vulkan-headers/src/include 
-I../../third_party/wayland/src/src -I../../third_party/wayland/include/src 
-I../../third_party/dawn/third_party/khronos/EGL-Registry/api -Wall -Wextra 
-Wimplicit-fallthrough -Wextra-semi -Wunreachable-code-aggressive 
-Wthread-safety -Wgnu -Wno-gnu-anonymous-struct 
-Wno-gnu-conditional-omitted-operand -Wno-gnu-include-next 
-Wno-gnu-label-as-value -Wno-gnu-redeclared-enum -Wno-gnu-statement-expression 
-Wno-gnu-zero-variadic-macro-arguments -Wno-zero-length-array 
-Wno-missing-field-initializers -Wno-unused-parameter -Wno-psabi 
-Wloop-analysis -Wno-unneeded-internal-declaration -Wno-cast-function-type 
-Wno-thread-safety-reference-return -Wshadow -Werror 
-fno-delete-null-pointer-checks -fno-ident -fno-strict-aliasing 
-fstack-protector -funwind-tables -fPIC -pthread -fcolor-diagnostics 
-fmerge-all-constants -fno-sized-deallocation 
-fcrash-diagnostics-dir=../../tools/clang/crashreports -mllvm 
-instcombine-lower-dbg-declare=0 -mllvm -split-threshold-for-reg-with-hint=0 
-ffp-contract=off -Wa,--crel,--allow-experimental-crel 
-fcomplete-member-pointers -m64 -msse3 -Wno-builtin-macro-redefined -D__DATE__= 
-D__TIME__= -D__TIMESTAMP__= -ffile-compilation-dir=. -no-canonical-prefixes 
-ftrivial-auto-var-init=pattern -O2 -fdata-sections -ffunction-sections 
-fno-unique-section-names -fno-math-errno -fno-omit-frame-pointer -g0 
-fvisibility=hidden -Wheader-hygiene -Wstring-conversion 
-Wtautological-overlap-compare 
-isystem../../build/linux/debian_bullseye_amd64-sysroot/usr/include/glib-2.0 
-isystem../../build/linux/debian_bullseye_amd64-sysroot/usr/lib/x86_64-linux-gnu/glib-2.0/include
 -DPROTOBUF_ALLOW_DEPRECATED=1 -Wno-inconsistent-missing-override 
-Wno-redundant-parens -Wno-invalid-offsetof -Wenum-compare-conditional 
-Wno-c++11-narrowing-const-reference 
-Wno-missing-template-arg-list-after-template-kw -Wno-dangling-assignment-gsl 
-Wno-nontrivial-memaccess -std=c++20 -Wno-trigraphs -gsimple-template-names 
-fno-exceptions -fno-rtti -nostdinc++ 
-isystem../../third_party/libc++/src/include 
-isystem../../third_party/libc++abi/src/include 
--sysroot=../../build/linux/debian_bullseye_amd64-sysroot 
-fvisibility-inlines-hidden -c 
../../third_party/daw

[clang] [Clang] skip default argument instantiation for non-defining friend declarations without specialization info to meet [dcl.fct.default] p4 (PR #113777)

2024-11-07 Thread Alan Zhao via cfe-commits

alanzhao1 wrote:

> Reverted. The issue looks like the instantiation of the default argument was 
> skipped, but without any previous error actually being produced, so it 
> proceeded to CodeGen with invalid AST.

Thanks! Still waiting on CReduce for that repro.

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


[clang] [llvm] Revert "[X86][AMX] Support AMX-AVX512" (PR #115570)

2024-11-08 Thread Alan Zhao via cfe-commits

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


[clang] [llvm] Revert "[X86][AMX] Support AMX-AVX512" (PR #115570)

2024-11-08 Thread Alan Zhao via cfe-commits

https://github.com/alanzhao1 created 
https://github.com/llvm/llvm-project/pull/115570

Reverts llvm/llvm-project#114070

Reason: Causes `immintrin.h` to fail to compile if `-msse` and `-mno-sse2` are 
passed to clang: 
https://github.com/llvm/llvm-project/pull/114070#issuecomment-2465926700

>From e06af1d045a57e93ebf3c86c4ac70aa752a93fa1 Mon Sep 17 00:00:00 2001
From: Alan Zhao 
Date: Fri, 8 Nov 2024 16:12:54 -0800
Subject: [PATCH] Revert "[X86][AMX] Support AMX-AVX512 (#114070)"

This reverts commit 58a17e1bbc54357385d0b89cfc5635e402c31ef6.
---
 clang/docs/ReleaseNotes.rst   |   1 -
 clang/include/clang/Basic/BuiltinsX86_64.def  |  13 -
 clang/include/clang/Driver/Options.td |   2 -
 clang/lib/Basic/Targets/X86.cpp   |   6 -
 clang/lib/Basic/Targets/X86.h |   1 -
 clang/lib/Headers/CMakeLists.txt  |   1 -
 clang/lib/Headers/amxavx512intrin.h   | 382 --
 clang/lib/Headers/immintrin.h |   4 -
 clang/lib/Sema/SemaX86.cpp|   6 -
 clang/test/CodeGen/X86/amx_avx512_api.c   |  52 ---
 clang/test/CodeGen/X86/amxavx512-builtins.c   |  41 --
 clang/test/CodeGen/attr-target-x86.c  |   8 +-
 clang/test/Driver/x86-target-features.c   |   7 -
 clang/test/Preprocessor/x86_target_features.c |  12 -
 llvm/include/llvm/IR/IntrinsicsX86.td |  51 ---
 .../llvm/TargetParser/X86TargetParser.def |   1 -
 llvm/lib/Target/X86/X86.td|   4 -
 llvm/lib/Target/X86/X86ExpandPseudo.cpp   |  67 +--
 llvm/lib/Target/X86/X86ISelLowering.cpp   |  76 
 llvm/lib/Target/X86/X86InstrAMX.td| 147 ---
 llvm/lib/Target/X86/X86InstrPredicates.td |   1 -
 llvm/lib/Target/X86/X86LowerAMXType.cpp   |  11 -
 llvm/lib/Target/X86/X86PreTileConfig.cpp  |  18 +-
 llvm/lib/TargetParser/Host.cpp|   1 -
 llvm/lib/TargetParser/X86TargetParser.cpp |   2 -
 .../CodeGen/X86/amx-across-func-tilemovrow.ll | 171 
 .../test/CodeGen/X86/amx-avx512-intrinsics.ll | 116 --
 .../CodeGen/X86/amx-tile-avx512-internals.ll  |  61 ---
 llvm/test/MC/Disassembler/X86/amx-avx512.txt  | 106 -
 llvm/test/MC/X86/amx-avx512-att.s | 105 -
 llvm/test/MC/X86/amx-avx512-intel.s   | 105 -
 31 files changed, 12 insertions(+), 1567 deletions(-)
 delete mode 100644 clang/lib/Headers/amxavx512intrin.h
 delete mode 100644 clang/test/CodeGen/X86/amx_avx512_api.c
 delete mode 100644 clang/test/CodeGen/X86/amxavx512-builtins.c
 delete mode 100644 llvm/test/CodeGen/X86/amx-across-func-tilemovrow.ll
 delete mode 100644 llvm/test/CodeGen/X86/amx-avx512-intrinsics.ll
 delete mode 100644 llvm/test/CodeGen/X86/amx-tile-avx512-internals.ll
 delete mode 100644 llvm/test/MC/Disassembler/X86/amx-avx512.txt
 delete mode 100644 llvm/test/MC/X86/amx-avx512-att.s
 delete mode 100644 llvm/test/MC/X86/amx-avx512-intel.s

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c3424e0e6f34c9..f82fbb73b12162 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -739,7 +739,6 @@ X86 Support
   * Supported intrinsics of ``_mm(256|512)_(mask(z))_loadrs_epi(8|16|32|64)``.
 - Support ISA of ``AMX-FP8``.
 - Support ISA of ``AMX-TRANSPOSE``.
-- Support ISA of ``AMX-AVX512``.
 
 Arm and AArch64 Support
 ^^^
diff --git a/clang/include/clang/Basic/BuiltinsX86_64.def 
b/clang/include/clang/Basic/BuiltinsX86_64.def
index 9f7462b1e0d962..d95e8455a304b6 100644
--- a/clang/include/clang/Basic/BuiltinsX86_64.def
+++ b/clang/include/clang/Basic/BuiltinsX86_64.def
@@ -133,12 +133,6 @@ TARGET_BUILTIN(__builtin_ia32_t2rpntlvwz0t1_internal, 
"vUsUsUsV256i*V256i*vC*z",
 TARGET_BUILTIN(__builtin_ia32_t2rpntlvwz1_internal, "vUsUsUsV256i*V256i*vC*z", 
"n", "amx-transpose")
 TARGET_BUILTIN(__builtin_ia32_t2rpntlvwz1t1_internal, 
"vUsUsUsV256i*V256i*vC*z", "n", "amx-transpose")
 TARGET_BUILTIN(__builtin_ia32_ttransposed_internal, "V256iUsUsV256i", "n", 
"amx-transpose")
-TARGET_BUILTIN(__builtin_ia32_tcvtrowd2ps_internal, "V16fUsUsV256iUi", "n", 
"amx-avx512,avx10.2-512")
-TARGET_BUILTIN(__builtin_ia32_tcvtrowps2pbf16h_internal, "V32yUsUsV256iUi", 
"n", "amx-avx512,avx10.2-512")
-TARGET_BUILTIN(__builtin_ia32_tcvtrowps2pbf16l_internal, "V32yUsUsV256iUi", 
"n", "amx-avx512,avx10.2-512")
-TARGET_BUILTIN(__builtin_ia32_tcvtrowps2phh_internal, "V32xUsUsV256iUi", "n", 
"amx-avx512,avx10.2-512")
-TARGET_BUILTIN(__builtin_ia32_tcvtrowps2phl_internal, "V32xUsUsV256iUi", "n", 
"amx-avx512,avx10.2-512")
-TARGET_BUILTIN(__builtin_ia32_tilemovrow_internal, "V16iUsUsV256iUi", "n", 
"amx-avx512,avx10.2-512")
 // AMX
 TARGET_BUILTIN(__builtin_ia32_tile_loadconfig, "vvC*", "n", "amx-tile")
 TARGET_BUILTIN(__builtin_ia32_tile_storeconfig, "vvC*", "n", "amx-tile")
@@ -165,13 +159,6 @@ TARGET_BUILTIN(__builtin_ia32_t2rpntlvwz1, "vIUcvC*z", 
"n", "amx-transpose")
 TARGET_BUILTIN(__builtin_ia32_t2rpntlvwz1t1, "vIUcvC*z", "n"

[clang] [llvm] [X86][AMX] Support AMX-AVX512 (PR #114070)

2024-11-08 Thread Alan Zhao via cfe-commits

alanzhao1 wrote:

Figured out a repro - `immintrin.h` doesn't compile if both `-msse` and 
`-mno-sse2` are passed to clang:

```
$ cat ~/src/test-mac.c
#include

$ bin/clang -msse -mno-sse2 -o /dev/null -c ~/src/test-mac.c
In file included from /usr/local/google/home/ayzhao/src/test-mac.c:1:
In file included from 
/usr/local/google/home/ayzhao/src/llvm-project/build/lib/clang/20/include/immintrin.h:660:
/usr/local/google/home/ayzhao/src/llvm-project/build/lib/clang/20/include/amxavx512intrin.h:240:19:
 error: unknown type name '__m512bh'
  240 | static __inline__ __m512bh __DEFAULT_FN_ATTRS_AVX512
  |   ^
/usr/local/google/home/ayzhao/src/llvm-project/build/lib/clang/20/include/amxavx512intrin.h:243:10:
 error: returning '__attribute__((__vector_size__(32 * sizeof(__bf16 
__bf16' (vector of 32 '__bf16' values) from a function with incompatible result 
type 'int'
  243 |   return __builtin_ia32_tcvtrowps2pbf16h_internal(m, n, src, u);
  |  ^~
/usr/local/google/home/ayzhao/src/llvm-project/build/lib/clang/20/include/amxavx512intrin.h:246:19:
 error: unknown type name '__m512bh'
  246 | static __inline__ __m512bh __DEFAULT_FN_ATTRS_AVX512
  |   ^
/usr/local/google/home/ayzhao/src/llvm-project/build/lib/clang/20/include/amxavx512intrin.h:249:10:
 error: returning '__attribute__((__vector_size__(32 * sizeof(__bf16 
__bf16' (vector of 32 '__bf16' values) from a function with incompatible result 
type 'int'
  249 |   return __builtin_ia32_tcvtrowps2pbf16l_internal(m, n, src, u);
  |  ^~
/usr/local/google/home/ayzhao/src/llvm-project/build/lib/clang/20/include/amxavx512intrin.h:252:19:
 error: unknown type name '__m512h'
  252 | static __inline__ __m512h __DEFAULT_FN_ATTRS_AVX512 
_tile_cvtrowps2phh_internal(
  |   ^
/usr/local/google/home/ayzhao/src/llvm-project/build/lib/clang/20/include/amxavx512intrin.h:254:10:
 error: returning '__attribute__((__vector_size__(32 * sizeof(_Float16 
_Float16' (vector of 32 '_Float16' values) from a function with incompatible 
result type 'int'
  254 |   return __builtin_ia32_tcvtrowps2phh_internal(m, n, src, u);
  |  ^~~
/usr/local/google/home/ayzhao/src/llvm-project/build/lib/clang/20/include/amxavx512intrin.h:257:19:
 error: unknown type name '__m512h'
  257 | static __inline__ __m512h __DEFAULT_FN_ATTRS_AVX512 
_tile_cvtrowps2phl_internal(
  |   ^
/usr/local/google/home/ayzhao/src/llvm-project/build/lib/clang/20/include/amxavx512intrin.h:259:10:
 error: returning '__attribute__((__vector_size__(32 * sizeof(_Float16 
_Float16' (vector of 32 '_Float16' values) from a function with incompatible 
result type 'int'
  259 |   return __builtin_ia32_tcvtrowps2phl_internal(m, n, src, u);
  |  ^~~
/usr/local/google/home/ayzhao/src/llvm-project/build/lib/clang/20/include/amxavx512intrin.h:302:8:
 error: unknown type name '__m512bh'
  302 | static __m512bh __tile_cvtrowps2pbf16h(__tile1024i src0, unsigned src1) 
{
  |^
/usr/local/google/home/ayzhao/src/llvm-project/build/lib/clang/20/include/amxavx512intrin.h:321:8:
 error: unknown type name '__m512bh'
  321 | static __m512bh __tile_cvtrowps2pbf16l(__tile1024i src0, unsigned src1) 
{
  |^
/usr/local/google/home/ayzhao/src/llvm-project/build/lib/clang/20/include/amxavx512intrin.h:340:8:
 error: unknown type name '__m512h'
  340 | static __m512h __tile_cvtrowps2phh(__tile1024i src0, unsigned src1) {
  |^
/usr/local/google/home/ayzhao/src/llvm-project/build/lib/clang/20/include/amxavx512intrin.h:359:8:
 error: unknown type name '__m512h'
  359 | static __m512h __tile_cvtrowps2phl(__tile1024i src0, unsigned src1) {
  |^
12 errors generated.
```

Test was on an x64 linux system.

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


[clang] [compiler-rt] Move interceptors for libresolv functions to MSan (PR #119071)

2024-12-18 Thread Alan Zhao via cfe-commits

alanzhao1 wrote:

Managed to reproduce it. This seems to break if the sysroot is set to the one 
Chrome uses. Our sysroot can be downloaded at 
https://commondatastorage.googleapis.com/chrome-linux-sysroot/dec7a3a0fc5b83b909cba1b6d119077e0429a138eadef6bf5a0f2e03b1904631

Command I used:

```
$ cmake -DLLVM_ENABLE_LLD=ON -DCMAKE_USE_LINKER=/usr/bin/lld  
-DCMAKE_C_COMPILER=/usr/bin/clang -DCMAKE_CXX_COMPILER=/usr/bin/clang++ 
-DLLVM_ENABLE_ZSTD=OFF -DLLVM_TARGETS_TO_BUILD='X86' 
-DLLVM_ENABLE_RUNTIMES='compiler-rt' -DCOMPILER_RT_BUILD_SANITIZERS=ON 
-DCOMPILER_RT_SANITIZERS_TO_BUILD='asan;dfsan;msan;hwasan;tsan;cfi' 
-DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_PROJECTS='clang' -DLLVM_ENABLE_PIC=OFF 
-DCMAKE_SYSROOT='/usr/local/google/home/ayzhao/src/chromium/src/third_party/llvm-build-tools/debian_bullseye_amd64_sysroot'
 
-DRUNTIMES_i386-unknown-linux-gnu_CMAKE_SYSROOT=/usr/local/google/home/ayzhao/src/chromium/src/third_party/llvm-build-tools/debian_bullseye_i386_sysroot
 
-DBUILTINS_i386-unknown-linux-gnu_CMAKE_SYSROOT=/usr/local/google/home/ayzhao/src/chromium/src/third_party/llvm-build-tools/debian_bullseye_i386_sysroot
 -DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON -G Ninja ../llvm

$ ninja check-runtimes
```

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


[clang] [clang-format] Fix misannotations of `<` in ternary expressions (PR #100980)

2025-01-16 Thread Alan Zhao via cfe-commits

alanzhao1 wrote:

FYI this change messes up formatting of angle brackets for member function 
template parameters.

See #123144

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


[clang] [llvm] Use global TimerGroups for both new pass manager and old pass manager timers (PR #130375)

2025-03-07 Thread Alan Zhao via cfe-commits

https://github.com/alanzhao1 created 
https://github.com/llvm/llvm-project/pull/130375

Additionally, remove the behavior for both pass manager's timer manager classes 
(`PassTimingInfo` for the old pass manager and `TimePassesHandler` for the new 
pass manager) where these classes would print the values of their timers upon 
destruction.

Currently, each pass manager manages their own `TimerGroup`s. This is 
problematic because of duplicate `TimerGroup`s (both pass managers have a 
`TimerGroup` for pass times with identical names and descriptions). The result 
is that in Clang, `-ftime-report` has two "Pass execution timing report" 
sections (one for the new pass manager which manages optimization passes, and 
one for the old pass manager which manages the backend). The result of this 
change is that Clang's `-ftime-report` now prints both optimization and backend 
pass timing info in a unified "Pass execution timing report" section.

Moving the ownership of the `TimerGroups` to globals also  makes it easier to 
implement JSON-formatted `-ftime-report`. This was not possible with the old 
structure because the two pass managers were created and destroyed in far parts 
of the codebase and outputting JSON requires the printing logic to be at the 
same place because of formatting.

Previous discourse discussion: 
https://discourse.llvm.org/t/difficulties-with-implementing-json-formatted-ftime-report/84353

>From b2b4d522a442867aa65655cac1a0ece02616252b Mon Sep 17 00:00:00 2001
From: Alan Zhao 
Date: Mon, 24 Feb 2025 11:10:04 -0800
Subject: [PATCH] Use global TimerGroups for both new pass manager and old pass
 manager timers

Additionally, remove the behavior for both pass manager's timer manager
classes (`PassTimingInfo` for the old pass manager and
`TimePassesHandler` for the new pass manager) where these classes would
print the values of their timers upon destruction.

Currently, each pass manager manages their own `TimerGroup`s. This is
problematic because of duplicate `TimerGroup`s (both pass managers have
a `TimerGroup` for pass times with identical names and descriptions).
The result is that in Clang, `-ftime-report` has two "Pass execution
timing report" sections (one for the new pass manager which manages
optimization passes, and one for the old pass manager which manages the
backend). The result of this change is that Clang's `-ftime-report` now
prints both optimization and backend pass timing info in a unified "Pass
execution timing report" section.

Moving the ownership of the `TimerGroups` to globals also  makes it
easier to implement JSON-formatted `-ftime-report`. This was not
possible with the old structure because the two pass managers were
created and destroyed in far parts of the codebase and outputting JSON
requires the printing logic to be at the same place because of
formatting.

Previous discourse discussion: 
https://discourse.llvm.org/t/difficulties-with-implementing-json-formatted-ftime-report/84353
---
 clang/test/Misc/time-passes.c |  1 -
 llvm/include/llvm/IR/PassTimingInfo.h | 12 ++
 llvm/include/llvm/Support/Timer.h | 11 +
 llvm/lib/IR/PassTimingInfo.cpp| 60 +--
 llvm/lib/Support/Timer.cpp| 42 +++
 llvm/unittests/IR/TimePassesTest.cpp  |  4 +-
 6 files changed, 79 insertions(+), 51 deletions(-)

diff --git a/clang/test/Misc/time-passes.c b/clang/test/Misc/time-passes.c
index 395da216aad42..c1669826b2268 100644
--- a/clang/test/Misc/time-passes.c
+++ b/clang/test/Misc/time-passes.c
@@ -19,6 +19,5 @@
 // NPM:   InstCombinePass{{$}}
 // NPM-NOT:   InstCombinePass #
 // TIME: Total{{$}}
-// NPM: Pass execution timing report
 
 int foo(int x, int y) { return x + y; }
diff --git a/llvm/include/llvm/IR/PassTimingInfo.h 
b/llvm/include/llvm/IR/PassTimingInfo.h
index 1148399943186..13947f7405245 100644
--- a/llvm/include/llvm/IR/PassTimingInfo.h
+++ b/llvm/include/llvm/IR/PassTimingInfo.h
@@ -39,19 +39,14 @@ Timer *getPassTimer(Pass *);
 /// This class implements -time-passes functionality for new pass manager.
 /// It provides the pass-instrumentation callbacks that measure the pass
 /// execution time. They collect timing info into individual timers as
-/// passes are being run. At the end of its life-time it prints the resulting
-/// timing report.
+/// passes are being run.
 class TimePassesHandler {
   /// Value of this type is capable of uniquely identifying pass invocations.
   /// It is a pair of string Pass-Identifier (which for now is common
   /// to all the instance of a given pass) + sequential invocation counter.
   using PassInvocationID = std::pair;
 
-  /// Groups of timers for passes and analyses.
-  TimerGroup PassTG;
-  TimerGroup AnalysisTG;
-
-  using TimerVector = llvm::SmallVector, 4>;
+  using TimerVector = llvm::SmallVector;
   /// Map of timers for pass invocations
   StringMap TimingData;
 
@@ -74,8 +69,7 @@ class TimePassesHandler {
   TimePassesHandler();
   TimePassesHandle

[clang] [llvm] Use global TimerGroups for both new pass manager and old pass manager timers (PR #130375)

2025-03-10 Thread Alan Zhao via cfe-commits

https://github.com/alanzhao1 updated 
https://github.com/llvm/llvm-project/pull/130375

>From b2b4d522a442867aa65655cac1a0ece02616252b Mon Sep 17 00:00:00 2001
From: Alan Zhao 
Date: Mon, 24 Feb 2025 11:10:04 -0800
Subject: [PATCH 1/3] Use global TimerGroups for both new pass manager and old
 pass manager timers

Additionally, remove the behavior for both pass manager's timer manager
classes (`PassTimingInfo` for the old pass manager and
`TimePassesHandler` for the new pass manager) where these classes would
print the values of their timers upon destruction.

Currently, each pass manager manages their own `TimerGroup`s. This is
problematic because of duplicate `TimerGroup`s (both pass managers have
a `TimerGroup` for pass times with identical names and descriptions).
The result is that in Clang, `-ftime-report` has two "Pass execution
timing report" sections (one for the new pass manager which manages
optimization passes, and one for the old pass manager which manages the
backend). The result of this change is that Clang's `-ftime-report` now
prints both optimization and backend pass timing info in a unified "Pass
execution timing report" section.

Moving the ownership of the `TimerGroups` to globals also  makes it
easier to implement JSON-formatted `-ftime-report`. This was not
possible with the old structure because the two pass managers were
created and destroyed in far parts of the codebase and outputting JSON
requires the printing logic to be at the same place because of
formatting.

Previous discourse discussion: 
https://discourse.llvm.org/t/difficulties-with-implementing-json-formatted-ftime-report/84353
---
 clang/test/Misc/time-passes.c |  1 -
 llvm/include/llvm/IR/PassTimingInfo.h | 12 ++
 llvm/include/llvm/Support/Timer.h | 11 +
 llvm/lib/IR/PassTimingInfo.cpp| 60 +--
 llvm/lib/Support/Timer.cpp| 42 +++
 llvm/unittests/IR/TimePassesTest.cpp  |  4 +-
 6 files changed, 79 insertions(+), 51 deletions(-)

diff --git a/clang/test/Misc/time-passes.c b/clang/test/Misc/time-passes.c
index 395da216aad42..c1669826b2268 100644
--- a/clang/test/Misc/time-passes.c
+++ b/clang/test/Misc/time-passes.c
@@ -19,6 +19,5 @@
 // NPM:   InstCombinePass{{$}}
 // NPM-NOT:   InstCombinePass #
 // TIME: Total{{$}}
-// NPM: Pass execution timing report
 
 int foo(int x, int y) { return x + y; }
diff --git a/llvm/include/llvm/IR/PassTimingInfo.h 
b/llvm/include/llvm/IR/PassTimingInfo.h
index 1148399943186..13947f7405245 100644
--- a/llvm/include/llvm/IR/PassTimingInfo.h
+++ b/llvm/include/llvm/IR/PassTimingInfo.h
@@ -39,19 +39,14 @@ Timer *getPassTimer(Pass *);
 /// This class implements -time-passes functionality for new pass manager.
 /// It provides the pass-instrumentation callbacks that measure the pass
 /// execution time. They collect timing info into individual timers as
-/// passes are being run. At the end of its life-time it prints the resulting
-/// timing report.
+/// passes are being run.
 class TimePassesHandler {
   /// Value of this type is capable of uniquely identifying pass invocations.
   /// It is a pair of string Pass-Identifier (which for now is common
   /// to all the instance of a given pass) + sequential invocation counter.
   using PassInvocationID = std::pair;
 
-  /// Groups of timers for passes and analyses.
-  TimerGroup PassTG;
-  TimerGroup AnalysisTG;
-
-  using TimerVector = llvm::SmallVector, 4>;
+  using TimerVector = llvm::SmallVector;
   /// Map of timers for pass invocations
   StringMap TimingData;
 
@@ -74,8 +69,7 @@ class TimePassesHandler {
   TimePassesHandler();
   TimePassesHandler(bool Enabled, bool PerRun = false);
 
-  /// Destructor handles the print action if it has not been handled before.
-  ~TimePassesHandler() { print(); }
+  ~TimePassesHandler() = default;
 
   /// Prints out timing information and then resets the timers.
   void print();
diff --git a/llvm/include/llvm/Support/Timer.h 
b/llvm/include/llvm/Support/Timer.h
index abe30451dd2f2..3e115df1500fe 100644
--- a/llvm/include/llvm/Support/Timer.h
+++ b/llvm/include/llvm/Support/Timer.h
@@ -169,6 +169,17 @@ struct NamedRegionTimer : public TimeRegion {
   explicit NamedRegionTimer(StringRef Name, StringRef Description,
 StringRef GroupName,
 StringRef GroupDescription, bool Enabled = true);
+
+  // Create or get a timer stored in the same global map as other timers owned
+  // by NamedRegionTimer.
+  static Timer &getNamedGroupTimer(StringRef Name, StringRef Description,
+   StringRef GroupName,
+   StringRef GroupDescription);
+
+  // Create or get a TimerGroup stored in the same global map owned by
+  // NamedRegionTimer.
+  static TimerGroup &getNamedGroupTimerGroup(StringRef GroupName,
+ StringRef GroupDescription);
 };
 
 /// The TimerGroup class is used to gro

[clang] [llvm] Reapply "Use global TimerGroups for both new pass manager and old pass manager timers" (#131173) (PR #131217)

2025-03-13 Thread Alan Zhao via cfe-commits

alanzhao1 wrote:

Looks like there's still some random bolt test failures going on. I think some 
test expectations need to be changed.

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


[clang] [llvm] Reapply "Use global TimerGroups for both new pass manager and old pas… (PR #131217)

2025-03-13 Thread Alan Zhao via cfe-commits

https://github.com/alanzhao1 created 
https://github.com/llvm/llvm-project/pull/131217

…s manager timers" (#131173)

This reverts commit 31ebe6647b7f1fc7f6778a5438175b12f82357ae.

The reason for the test failure is likely due to
`Name2PairMap::getTimerGroup(...)` not holding a lock.

>From 3734f893ba427994204f25c2604f2a2c6fcc86d9 Mon Sep 17 00:00:00 2001
From: Alan Zhao 
Date: Thu, 13 Mar 2025 10:50:17 -0700
Subject: [PATCH] Reapply "Use global TimerGroups for both new pass manager and
 old pass manager timers" (#131173)

This reverts commit 31ebe6647b7f1fc7f6778a5438175b12f82357ae.

The reason for the test failure is likely due to
`Name2PairMap::getTimerGroup(...)` not holding a lock.
---
 clang/test/Misc/time-passes.c |  1 -
 llvm/include/llvm/IR/PassTimingInfo.h | 18 +---
 llvm/include/llvm/Support/Timer.h |  5 +
 llvm/lib/IR/PassTimingInfo.cpp| 30 ---
 llvm/lib/Support/Timer.cpp| 27 +++-
 llvm/unittests/IR/TimePassesTest.cpp  |  4 ++--
 6 files changed, 49 insertions(+), 36 deletions(-)

diff --git a/clang/test/Misc/time-passes.c b/clang/test/Misc/time-passes.c
index 395da216aad42..c1669826b2268 100644
--- a/clang/test/Misc/time-passes.c
+++ b/clang/test/Misc/time-passes.c
@@ -19,6 +19,5 @@
 // NPM:   InstCombinePass{{$}}
 // NPM-NOT:   InstCombinePass #
 // TIME: Total{{$}}
-// NPM: Pass execution timing report
 
 int foo(int x, int y) { return x + y; }
diff --git a/llvm/include/llvm/IR/PassTimingInfo.h 
b/llvm/include/llvm/IR/PassTimingInfo.h
index 1148399943186..b47ba7f16ef37 100644
--- a/llvm/include/llvm/IR/PassTimingInfo.h
+++ b/llvm/include/llvm/IR/PassTimingInfo.h
@@ -39,8 +39,7 @@ Timer *getPassTimer(Pass *);
 /// This class implements -time-passes functionality for new pass manager.
 /// It provides the pass-instrumentation callbacks that measure the pass
 /// execution time. They collect timing info into individual timers as
-/// passes are being run. At the end of its life-time it prints the resulting
-/// timing report.
+/// passes are being run.
 class TimePassesHandler {
   /// Value of this type is capable of uniquely identifying pass invocations.
   /// It is a pair of string Pass-Identifier (which for now is common
@@ -48,8 +47,10 @@ class TimePassesHandler {
   using PassInvocationID = std::pair;
 
   /// Groups of timers for passes and analyses.
-  TimerGroup PassTG;
-  TimerGroup AnalysisTG;
+  TimerGroup &PassTG =
+  NamedRegionTimer::getNamedTimerGroup(PassGroupName, PassGroupDesc);
+  TimerGroup &AnalysisTG = NamedRegionTimer::getNamedTimerGroup(
+  AnalysisGroupName, AnalysisGroupDesc);
 
   using TimerVector = llvm::SmallVector, 4>;
   /// Map of timers for pass invocations
@@ -71,12 +72,15 @@ class TimePassesHandler {
   bool PerRun;
 
 public:
+  static constexpr StringRef PassGroupName = "pass";
+  static constexpr StringRef AnalysisGroupName = "analysis";
+  static constexpr StringRef PassGroupDesc = "Pass execution timing report";
+  static constexpr StringRef AnalysisGroupDesc =
+  "Analysis execution timing report";
+
   TimePassesHandler();
   TimePassesHandler(bool Enabled, bool PerRun = false);
 
-  /// Destructor handles the print action if it has not been handled before.
-  ~TimePassesHandler() { print(); }
-
   /// Prints out timing information and then resets the timers.
   void print();
 
diff --git a/llvm/include/llvm/Support/Timer.h 
b/llvm/include/llvm/Support/Timer.h
index abe30451dd2f2..5a5082b6718ed 100644
--- a/llvm/include/llvm/Support/Timer.h
+++ b/llvm/include/llvm/Support/Timer.h
@@ -169,6 +169,11 @@ struct NamedRegionTimer : public TimeRegion {
   explicit NamedRegionTimer(StringRef Name, StringRef Description,
 StringRef GroupName,
 StringRef GroupDescription, bool Enabled = true);
+
+  // Create or get a TimerGroup stored in the same global map owned by
+  // NamedRegionTimer.
+  static TimerGroup &getNamedTimerGroup(StringRef GroupName,
+StringRef GroupDescription);
 };
 
 /// The TimerGroup class is used to group together related timers into a single
diff --git a/llvm/lib/IR/PassTimingInfo.cpp b/llvm/lib/IR/PassTimingInfo.cpp
index 46db2c74a5c76..4e27086e97ac5 100644
--- a/llvm/lib/IR/PassTimingInfo.cpp
+++ b/llvm/lib/IR/PassTimingInfo.cpp
@@ -63,16 +63,9 @@ class PassTimingInfo {
 private:
   StringMap PassIDCountMap; ///< Map that counts instances of passes
   DenseMap> TimingData; ///< timers for 
pass instances
-  TimerGroup TG;
+  TimerGroup *PassTG = nullptr;
 
 public:
-  /// Default constructor for yet-inactive timeinfo.
-  /// Use \p init() to activate it.
-  PassTimingInfo();
-
-  /// Print out timing information and release timers.
-  ~PassTimingInfo();
-
   /// Initializes the static \p TheTimeInfo member to a non-null value when
   /// -time-passes is enabled. Leaves it null otherwise.
   ///
@@ -94,14 +87,6 @@ class PassTimingInfo

[clang] [llvm] Reapply "Use global TimerGroups for both new pass manager and old pass manager timers" (#131173) (PR #131217)

2025-03-13 Thread Alan Zhao via cfe-commits

alanzhao1 wrote:

Let's wait until CI passes before merging as the test repro is kind of flaky on 
my machine.

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


[clang] [llvm] Reapply "Use global TimerGroups for both new pass manager and old pas… (PR #131217)

2025-03-13 Thread Alan Zhao via cfe-commits

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


[clang] [llvm] Use global TimerGroups for both new pass manager and old pass manager timers (PR #130375)

2025-03-13 Thread Alan Zhao via cfe-commits

alanzhao1 wrote:

Hmm...the bot breakages look like LLD test failures. Will investigate further.

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


[clang] [llvm] Use global TimerGroups for both new pass manager and old pass manager timers (PR #130375)

2025-03-13 Thread Alan Zhao via cfe-commits

alanzhao1 wrote:

> Hmm...the bot breakages look like LLD test failures. Will investigate further.

Note to self: add `cross-project-tests` to `LLVM_ENABLE_PROJECTS`to repro; I 
had no idea that existed.

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


[clang] [llvm] Use global TimerGroups for both new pass manager and old pass manager timers (PR #130375)

2025-03-13 Thread Alan Zhao via cfe-commits

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


[clang] [llvm] Use global TimerGroups for both new pass manager and old pass manager timers (PR #130375)

2025-03-12 Thread Alan Zhao via cfe-commits


@@ -39,19 +39,20 @@ Timer *getPassTimer(Pass *);
 /// This class implements -time-passes functionality for new pass manager.
 /// It provides the pass-instrumentation callbacks that measure the pass
 /// execution time. They collect timing info into individual timers as
-/// passes are being run. At the end of its life-time it prints the resulting
-/// timing report.
+/// passes are being run.
 class TimePassesHandler {
   /// Value of this type is capable of uniquely identifying pass invocations.
   /// It is a pair of string Pass-Identifier (which for now is common
   /// to all the instance of a given pass) + sequential invocation counter.
   using PassInvocationID = std::pair;
 
   /// Groups of timers for passes and analyses.
-  TimerGroup PassTG;
-  TimerGroup AnalysisTG;
+  TimerGroup &PassTG =
+  NamedRegionTimer::getNamedTimerGroup(PassGroupName, PassGroupDesc);
+  TimerGroup &AnalysisTG = NamedRegionTimer::getNamedTimerGroup(
+  AnalysisGroupName, AnalysisGroupDesc);
 
-  using TimerVector = llvm::SmallVector, 4>;
+  using TimerVector = llvm::SmallVector;

alanzhao1 wrote:

I mean this is sort of the end result we want - we need the timers to be 
accessible outside of the pass manager's lifetime.

It's also somewhat debatable whether or not the there is a memory leak since 
the TimerGroups store pointers to their timers anyways.

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


[clang] [llvm] Use global TimerGroups for both new pass manager and old pass manager timers (PR #130375)

2025-03-12 Thread Alan Zhao via cfe-commits


@@ -39,19 +39,20 @@ Timer *getPassTimer(Pass *);
 /// This class implements -time-passes functionality for new pass manager.
 /// It provides the pass-instrumentation callbacks that measure the pass
 /// execution time. They collect timing info into individual timers as
-/// passes are being run. At the end of its life-time it prints the resulting
-/// timing report.
+/// passes are being run.
 class TimePassesHandler {
   /// Value of this type is capable of uniquely identifying pass invocations.
   /// It is a pair of string Pass-Identifier (which for now is common
   /// to all the instance of a given pass) + sequential invocation counter.
   using PassInvocationID = std::pair;
 
   /// Groups of timers for passes and analyses.
-  TimerGroup PassTG;
-  TimerGroup AnalysisTG;
+  TimerGroup &PassTG =
+  NamedRegionTimer::getNamedTimerGroup(PassGroupName, PassGroupDesc);
+  TimerGroup &AnalysisTG = NamedRegionTimer::getNamedTimerGroup(
+  AnalysisGroupName, AnalysisGroupDesc);
 
-  using TimerVector = llvm::SmallVector, 4>;
+  using TimerVector = llvm::SmallVector;

alanzhao1 wrote:

SG, I'll wait until that gets merged and then I'll pull it into this PR.

Note to self: even if the timers themselves are destroyed, the timer values are 
still preserved in the TimerGroup.

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


[clang] [llvm] Reapply "Use global TimerGroups for both new pass manager and old pass manager timers" (#131173) (PR #131217)

2025-03-15 Thread Alan Zhao via cfe-commits

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


[clang] [clang] Automatically add the `returns_twice` attribute to certain functions even if `-fno-builtin` is set (PR #133511)

2025-04-05 Thread Alan Zhao via cfe-commits

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


[clang] [clang] Automatically add the `returns_twice` attribute to certain functions even if `-fno-builtin` is set (PR #133511)

2025-04-05 Thread Alan Zhao via cfe-commits

https://github.com/alanzhao1 created 
https://github.com/llvm/llvm-project/pull/133511

Certain functions require the `returns_twice` attribute in order to produce 
correct codegen. However, `-fno-builtin` removes all knowledge of functions 
that require this attribute, so this PR modifies Clang to add the 
`returns_twice` attribute even if `-fno-builtin` is set. This behavior is also 
consistent with what GCC does.

It's not (easily) possible to get the builtin information from `Builtins.td` 
because `-fno-builtin` causes Clang to never initialize any builtins, so 
functions never get tokenized as functions/builtins that require 
`returns_twice`. Therefore, the most straightforward solution is to explicitly 
hard code the function names that require `returns_twice`.

Fixes #122840

>From f4f5d88d287600c40746f16c008ed95d6838f9ff Mon Sep 17 00:00:00 2001
From: Alan Zhao 
Date: Fri, 28 Mar 2025 12:53:15 -0700
Subject: [PATCH] [clang] Automatically add the `returns_twice` attribute to
 certain functions even if `-fno-builtin` is set

Certain functions require the `returns_twice` attribute in order to
produce correct codegen. However, `-fno-builtin` removes all knowledge
of functions that require this attribute, so this PR modifies Clang to
add the `returns_twice` attribute even if `-fno-builtin` is set. This
behavior is also consistent with what GCC does.

It's not (easily) possible to get the builtin information from
`Builtins.td` because `-fno-builtin` causes Clang to never initialize
any builtins, so functions never get tokenized as functions/builtins
that require `returns_twice`. Therefore, the most straightforward
solution is to explicitly hard code the function names that require
`returns_twice`.

Fixes #122840
---
 clang/lib/CodeGen/CGCall.cpp  |  9 +
 clang/test/CodeGen/2003-08-20-vfork-bug.c |  5 -
 clang/test/CodeGen/setjmp.c   | 15 +++
 3 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 7aa77e55dbfcc..76119617f22e6 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -2607,6 +2607,15 @@ void CodeGenModule::ConstructAttributeList(StringRef 
Name,
 if (shouldDisableTailCalls())
   FuncAttrs.addAttribute("disable-tail-calls", "true");
 
+// These functions require the returns_twice attribute for correct codegen,
+// but the attribute may not be added if -fno-builtin is specified. We
+// explicitly add that attribute here.
+static const llvm::StringSet<> ReturnsTwiceFn{
+"_setjmpex", "setjmp",  "_setjmp", "vfork",
+"sigsetjmp", "__sigsetjmp", "savectx", "getcontext"};
+if (ReturnsTwiceFn.contains(Name))
+  FuncAttrs.addAttribute(llvm::Attribute::ReturnsTwice);
+
 // CPU/feature overrides.  addDefaultFunctionDefinitionAttributes
 // handles these separately to set them based on the global defaults.
 GetCPUAndFeaturesAttributes(CalleeInfo.getCalleeDecl(), FuncAttrs);
diff --git a/clang/test/CodeGen/2003-08-20-vfork-bug.c 
b/clang/test/CodeGen/2003-08-20-vfork-bug.c
index 4966ab20904d4..438604f321da3 100644
--- a/clang/test/CodeGen/2003-08-20-vfork-bug.c
+++ b/clang/test/CodeGen/2003-08-20-vfork-bug.c
@@ -1,5 +1,8 @@
-// RUN: %clang_cc1 -emit-llvm %s  -o /dev/null
+// RUN: %clang_cc1 -x c %s -triple x86_64-linux-gnu -emit-llvm -o - | 
FileCheck %s
+// RUN: %clang_cc1 -x c %s -triple x86_64-linux-gnu -emit-llvm -fno-builtin -o 
- | FileCheck %s
 
+// CHECK: ; Function Attrs: returns_twice
+// CHECK-NEXT: declare {{.*}} @vfork(
 extern int vfork(void);
 void test() {
   vfork();
diff --git a/clang/test/CodeGen/setjmp.c b/clang/test/CodeGen/setjmp.c
index 77dde35e69cae..00341e459941a 100644
--- a/clang/test/CodeGen/setjmp.c
+++ b/clang/test/CodeGen/setjmp.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -x c %s -triple x86_64-linux-gnu -emit-llvm -o - | 
FileCheck %s
+// RUN: %clang_cc1 -x c %s -triple x86_64-linux-gnu -emit-llvm -fno-builtin -o 
- | FileCheck %s
 // RUN: %clang_cc1 -x c++ %s -triple x86_64-linux-gnu -emit-llvm -o - | 
FileCheck %s
 
 #ifdef __cplusplus
@@ -6,13 +7,17 @@ extern "C" {
 #endif
 
 struct __jmp_buf_tag { int n; };
+struct __ucontext_t_tag { int n; };
 int setjmp(struct __jmp_buf_tag*);
 int sigsetjmp(struct __jmp_buf_tag*, int);
 int _setjmp(struct __jmp_buf_tag*);
 int __sigsetjmp(struct __jmp_buf_tag*, int);
+int _setjmpex(struct __jmp_buf_tag* env);
+int getcontext(struct __ucontext_t_tag*);
 
 typedef struct __jmp_buf_tag jmp_buf[1];
 typedef struct __jmp_buf_tag sigjmp_buf[1];
+typedef struct __ucontext_t_tag ucontext_t[1];
 
 #ifdef __cplusplus
 }
@@ -20,6 +25,7 @@ typedef struct __jmp_buf_tag sigjmp_buf[1];
 
 void f(void) {
   jmp_buf jb;
+  ucontext_t ut;
   // CHECK: call {{.*}}@setjmp(
   setjmp(jb);
   // CHECK: call {{.*}}@sigsetjmp(
@@ -28,6 +34,10 @@ void f(void) {
   _setjmp(jb);
   // CHECK: call {{.*}}@__sigsetjmp(
   __sigsetjmp(jb, 0);
+  // CHECK: call {{