[clang] [clang] Sequence C++20 Parenthesized List Init (PR #83476)

2024-03-05 Thread via cfe-commits

github-actions[bot] wrote:



@vapdrs Congratulations on having your first Pull Request (PR) merged into the 
LLVM Project!

Your changes will be combined with recent changes from other authors, then 
tested
by our [build bots](https://lab.llvm.org/buildbot/). If there is a problem with 
a build, you may recieve a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as
the builds can include changes from many authors. It is not uncommon for your
change to be included in a build that fails due to someone else's changes, or
infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail 
[here](https://llvm.org/docs/MyFirstTypoFix.html#myfirsttypofix-issues-after-landing-your-pr).

If your change does cause a problem, it may be reverted, or you can revert it 
yourself.
This is a normal part of [LLVM 
development](https://llvm.org/docs/DeveloperPolicy.html#patch-reversion-policy).
 You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are 
working as expected, well done!


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


[clang] [clang] Sequence C++20 Parenthesized List Init (PR #83476)

2024-03-05 Thread via cfe-commits

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


[clang] [clang] Sequence C++20 Parenthesized List Init (PR #83476)

2024-03-05 Thread Douglas Deslauriers via cfe-commits

vapdrs wrote:

> @vapdrs Do you need us to merge that for you? Thanks

Yes, I do not have write access to the repository. Thank you!

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


[clang] [clang] Sequence C++20 Parenthesized List Init (PR #83476)

2024-03-05 Thread via cfe-commits

cor3ntin wrote:

@vapdrs Do you need us to merge that for you? Thanks

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


[clang] [clang] Sequence C++20 Parenthesized List Init (PR #83476)

2024-03-04 Thread Shafik Yaghmour via cfe-commits

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


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


[clang] [clang] Sequence C++20 Parenthesized List Init (PR #83476)

2024-03-01 Thread Douglas Deslauriers via cfe-commits

https://github.com/vapdrs updated 
https://github.com/llvm/llvm-project/pull/83476

>From f66254c6be64a7270ce2df8556c540344ade0619 Mon Sep 17 00:00:00 2001
From: Douglas Deslauriers 
Date: Thu, 29 Feb 2024 20:18:34 +
Subject: [PATCH] [clang] Sequence C++20 Parenthesized List Init

Parenthesized list intializers are sequenced operations, see C++20
[decl.init]p16.5 and [decl.init]p16.6.2.2 for more details.

Fixes #83474
---
 clang/lib/Sema/SemaChecking.cpp   | 30 +--
 .../warn-unsequenced-paren-list-init.cpp  | 15 ++
 2 files changed, 29 insertions(+), 16 deletions(-)
 create mode 100644 clang/test/SemaCXX/warn-unsequenced-paren-list-init.cpp

diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 7be2b31df2413f..e14b8600818c1b 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -17617,20 +17617,8 @@ class SequenceChecker : public 
ConstEvaluatedExprVisitor {
   return VisitExpr(CCE);
 
 // In C++11, list initializations are sequenced.
-SmallVector Elts;
-SequenceTree::Seq Parent = Region;
-for (CXXConstructExpr::const_arg_iterator I = CCE->arg_begin(),
-  E = CCE->arg_end();
- I != E; ++I) {
-  Region = Tree.allocate(Parent);
-  Elts.push_back(Region);
-  Visit(*I);
-}
-
-// Forget that the initializers are sequenced.
-Region = Parent;
-for (unsigned I = 0; I < Elts.size(); ++I)
-  Tree.merge(Elts[I]);
+SequenceExpressionsInOrder(
+llvm::ArrayRef(CCE->getArgs(), CCE->getNumArgs()));
   }
 
   void VisitInitListExpr(const InitListExpr *ILE) {
@@ -17638,10 +17626,20 @@ class SequenceChecker : public 
ConstEvaluatedExprVisitor {
   return VisitExpr(ILE);
 
 // In C++11, list initializations are sequenced.
+SequenceExpressionsInOrder(ILE->inits());
+  }
+
+  void VisitCXXParenListInitExpr(const CXXParenListInitExpr *PLIE) {
+// C++20 parenthesized list initializations are sequenced. See C++20
+// [decl.init.general]p16.5 and [decl.init.general]p16.6.2.2.
+SequenceExpressionsInOrder(PLIE->getInitExprs());
+  }
+
+private:
+  void SequenceExpressionsInOrder(ArrayRef ExpressionList) {
 SmallVector Elts;
 SequenceTree::Seq Parent = Region;
-for (unsigned I = 0; I < ILE->getNumInits(); ++I) {
-  const Expr *E = ILE->getInit(I);
+for (const Expr *E : ExpressionList) {
   if (!E)
 continue;
   Region = Tree.allocate(Parent);
diff --git a/clang/test/SemaCXX/warn-unsequenced-paren-list-init.cpp 
b/clang/test/SemaCXX/warn-unsequenced-paren-list-init.cpp
new file mode 100644
index 00..5aeeb45f81e226
--- /dev/null
+++ b/clang/test/SemaCXX/warn-unsequenced-paren-list-init.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++20 -Wno-unused -Wunsequenced -verify 
%s
+
+struct A {
+  int x, y;
+};
+
+void test() {
+  int a = 0;
+
+  A agg1( a++, a++ ); // no warning
+  A agg2( a++ + a, a++ ); // expected-warning {{unsequenced modification and 
access to 'a'}}
+
+  int arr1[]( a++, a++ ); // no warning
+  int arr2[]( a++ + a, a++ ); // expected-warning {{unsequenced modification 
and access to 'a'}}
+}

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


[clang] [clang] Sequence C++20 Parenthesized List Init (PR #83476)

2024-03-01 Thread Douglas Deslauriers via cfe-commits

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


[clang] [clang] Sequence C++20 Parenthesized List Init (PR #83476)

2024-02-29 Thread Shafik Yaghmour via cfe-commits

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


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


[clang] [clang] Sequence C++20 Parenthesized List Init (PR #83476)

2024-02-29 Thread Shafik Yaghmour via cfe-commits


@@ -17615,31 +17615,28 @@ class SequenceChecker : public 
ConstEvaluatedExprVisitor {
   return VisitExpr(CCE);
 
 // In C++11, list initializations are sequenced.
-SmallVector Elts;
-SequenceTree::Seq Parent = Region;
-for (CXXConstructExpr::const_arg_iterator I = CCE->arg_begin(),
-  E = CCE->arg_end();
- I != E; ++I) {
-  Region = Tree.allocate(Parent);
-  Elts.push_back(Region);
-  Visit(*I);
-}
-
-// Forget that the initializers are sequenced.
-Region = Parent;
-for (unsigned I = 0; I < Elts.size(); ++I)
-  Tree.merge(Elts[I]);
+SequenceExpressionsInOrder({CCE->getArgs(), CCE->getNumArgs()});

shafik wrote:

I took me a bit of checking to convince myself this was doing the right thing. 
It might be nice to refactor `CXXConstructExpr` to have an a member that does 
the same as `ILE->inits()` and returns an `ArrayRef`. It looks like do similar 
things to create an `ArrayRef` in other places as well but probably should be a 
second PR.

Maybe change this to `llvm::ArrayRef(CCE->getArgs(), CCE->getNumArgs())` to 
make it more explicit for now.

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


[clang] [clang] Sequence C++20 Parenthesized List Init (PR #83476)

2024-02-29 Thread Shafik Yaghmour via cfe-commits

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


[clang] [clang] Sequence C++20 Parenthesized List Init (PR #83476)

2024-02-29 Thread Shafik Yaghmour via cfe-commits

https://github.com/shafik commented:

LGTM after addressing comment.

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


[clang] [clang] Sequence C++20 Parenthesized List Init (PR #83476)

2024-02-29 Thread Douglas Deslauriers via cfe-commits

https://github.com/vapdrs updated 
https://github.com/llvm/llvm-project/pull/83476

>From cc14e7a3320c36295514b75108e4da481d2f6b99 Mon Sep 17 00:00:00 2001
From: Douglas Deslauriers 
Date: Thu, 29 Feb 2024 20:18:34 +
Subject: [PATCH] [clang] Sequence C++20 Parenthesized List Init

Parenthesized list intializers are sequenced operations, see C++20
[decl.init]p16.5 and [decl.init]p16.6.2.2 for more details.

Fixes #83474
---
 clang/lib/Sema/SemaChecking.cpp   | 29 +--
 .../warn-unsequenced-paren-list-init.cpp  | 15 ++
 2 files changed, 28 insertions(+), 16 deletions(-)
 create mode 100644 clang/test/SemaCXX/warn-unsequenced-paren-list-init.cpp

diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 690bdaa63d058b..de9569c799b121 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -17615,20 +17615,7 @@ class SequenceChecker : public 
ConstEvaluatedExprVisitor {
   return VisitExpr(CCE);
 
 // In C++11, list initializations are sequenced.
-SmallVector Elts;
-SequenceTree::Seq Parent = Region;
-for (CXXConstructExpr::const_arg_iterator I = CCE->arg_begin(),
-  E = CCE->arg_end();
- I != E; ++I) {
-  Region = Tree.allocate(Parent);
-  Elts.push_back(Region);
-  Visit(*I);
-}
-
-// Forget that the initializers are sequenced.
-Region = Parent;
-for (unsigned I = 0; I < Elts.size(); ++I)
-  Tree.merge(Elts[I]);
+SequenceExpressionsInOrder({CCE->getArgs(), CCE->getNumArgs()});
   }
 
   void VisitInitListExpr(const InitListExpr *ILE) {
@@ -17636,10 +17623,20 @@ class SequenceChecker : public 
ConstEvaluatedExprVisitor {
   return VisitExpr(ILE);
 
 // In C++11, list initializations are sequenced.
+SequenceExpressionsInOrder(ILE->inits());
+  }
+
+  void VisitCXXParenListInitExpr(const CXXParenListInitExpr *PLIE) {
+// C++20 parenthesized list initializations are sequenced. See C++20
+// [decl.init.general]p16.5 and [decl.init.general]p16.6.2.2.
+SequenceExpressionsInOrder(PLIE->getInitExprs());
+  }
+
+private:
+  void SequenceExpressionsInOrder(ArrayRef ExpressionList) {
 SmallVector Elts;
 SequenceTree::Seq Parent = Region;
-for (unsigned I = 0; I < ILE->getNumInits(); ++I) {
-  const Expr *E = ILE->getInit(I);
+for (const Expr *E : ExpressionList) {
   if (!E)
 continue;
   Region = Tree.allocate(Parent);
diff --git a/clang/test/SemaCXX/warn-unsequenced-paren-list-init.cpp 
b/clang/test/SemaCXX/warn-unsequenced-paren-list-init.cpp
new file mode 100644
index 00..5aeeb45f81e226
--- /dev/null
+++ b/clang/test/SemaCXX/warn-unsequenced-paren-list-init.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++20 -Wno-unused -Wunsequenced -verify 
%s
+
+struct A {
+  int x, y;
+};
+
+void test() {
+  int a = 0;
+
+  A agg1( a++, a++ ); // no warning
+  A agg2( a++ + a, a++ ); // expected-warning {{unsequenced modification and 
access to 'a'}}
+
+  int arr1[]( a++, a++ ); // no warning
+  int arr2[]( a++ + a, a++ ); // expected-warning {{unsequenced modification 
and access to 'a'}}
+}

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


[clang] [clang] Sequence C++20 Parenthesized List Init (PR #83476)

2024-02-29 Thread Douglas Deslauriers via cfe-commits


@@ -17626,6 +17626,25 @@ class SequenceChecker : public 
ConstEvaluatedExprVisitor {
 for (unsigned I = 0; I < Elts.size(); ++I)
   Tree.merge(Elts[I]);
   }
+
+  void VisitCXXParenListInitExpr(const CXXParenListInitExpr *PLIE) {
+// C++20 parenthesized list initializations are sequenced. See C++20
+// [decl.init]p17.5 and [decl.init]p17.6.2.2
+SmallVector Elts;
+SequenceTree::Seq Parent = Region;
+for (const Expr *E : PLIE->getInitExprs()) {
+  if (!E)
+continue;
+  Region = Tree.allocate(Parent);
+  Elts.push_back(Region);
+  Visit(E);
+}
+
+// Forget that the initializers are sequenced.
+Region = Parent;
+for (unsigned I = 0; I < Elts.size(); ++I)
+  Tree.merge(Elts[I]);
+  }

vapdrs wrote:

I can do you one better and also factor out code in `VisitCXXConstructExpr` 
too, however that does call into question the comment `// In C++11, list 
initializations are sequenced.` in that function which seems to be copy pasted 
from `VisitInitListExpr`. So if you want me to remove that, let me know.

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


[clang] [clang] Sequence C++20 Parenthesized List Init (PR #83476)

2024-02-29 Thread Douglas Deslauriers via cfe-commits


@@ -17626,6 +17626,25 @@ class SequenceChecker : public 
ConstEvaluatedExprVisitor {
 for (unsigned I = 0; I < Elts.size(); ++I)
   Tree.merge(Elts[I]);
   }
+
+  void VisitCXXParenListInitExpr(const CXXParenListInitExpr *PLIE) {
+// C++20 parenthesized list initializations are sequenced. See C++20
+// [decl.init]p17.5 and [decl.init]p17.6.2.2

vapdrs wrote:

Resolved, also updated issue and PR description

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


[clang] [clang] Sequence C++20 Parenthesized List Init (PR #83476)

2024-02-29 Thread Douglas Deslauriers via cfe-commits

https://github.com/vapdrs updated 
https://github.com/llvm/llvm-project/pull/83476

>From 85958bdf181b0cb79716a35bc4f3248e8f31c527 Mon Sep 17 00:00:00 2001
From: Douglas Deslauriers 
Date: Thu, 29 Feb 2024 20:18:34 +
Subject: [PATCH] [clang] Sequence C++20 Parenthesized List Init

Parenthesized list intializers are sequenced operations, see C++20
[decl.init]p16.5 and [decl.init]p16.6.2.2 for more details.

Fixes #83474
---
 clang/lib/Sema/SemaChecking.cpp   | 29 +--
 .../warn-unsequenced-paren-list-init.cpp  | 15 ++
 2 files changed, 28 insertions(+), 16 deletions(-)
 create mode 100644 clang/test/SemaCXX/warn-unsequenced-paren-list-init.cpp

diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 016e9830662042..4a120a7e310819 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -17589,20 +17589,7 @@ class SequenceChecker : public 
ConstEvaluatedExprVisitor {
   return VisitExpr(CCE);
 
 // In C++11, list initializations are sequenced.
-SmallVector Elts;
-SequenceTree::Seq Parent = Region;
-for (CXXConstructExpr::const_arg_iterator I = CCE->arg_begin(),
-  E = CCE->arg_end();
- I != E; ++I) {
-  Region = Tree.allocate(Parent);
-  Elts.push_back(Region);
-  Visit(*I);
-}
-
-// Forget that the initializers are sequenced.
-Region = Parent;
-for (unsigned I = 0; I < Elts.size(); ++I)
-  Tree.merge(Elts[I]);
+SequenceExpressionsInOrder({CCE->getArgs(), CCE->getNumArgs()});
   }
 
   void VisitInitListExpr(const InitListExpr *ILE) {
@@ -17610,10 +17597,20 @@ class SequenceChecker : public 
ConstEvaluatedExprVisitor {
   return VisitExpr(ILE);
 
 // In C++11, list initializations are sequenced.
+SequenceExpressionsInOrder(ILE->inits());
+  }
+
+  void VisitCXXParenListInitExpr(const CXXParenListInitExpr *PLIE) {
+// C++20 parenthesized list initializations are sequenced. See C++20
+// [decl.init.general]p16.5 and [decl.init.general]p16.6.2.2.
+SequenceExpressionsInOrder(PLIE->getInitExprs());
+  }
+
+private:
+  void SequenceExpressionsInOrder(ArrayRef ExpressionList) {
 SmallVector Elts;
 SequenceTree::Seq Parent = Region;
-for (unsigned I = 0; I < ILE->getNumInits(); ++I) {
-  const Expr *E = ILE->getInit(I);
+for (const Expr *E : ExpressionList) {
   if (!E)
 continue;
   Region = Tree.allocate(Parent);
diff --git a/clang/test/SemaCXX/warn-unsequenced-paren-list-init.cpp 
b/clang/test/SemaCXX/warn-unsequenced-paren-list-init.cpp
new file mode 100644
index 00..5aeeb45f81e226
--- /dev/null
+++ b/clang/test/SemaCXX/warn-unsequenced-paren-list-init.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++20 -Wno-unused -Wunsequenced -verify 
%s
+
+struct A {
+  int x, y;
+};
+
+void test() {
+  int a = 0;
+
+  A agg1( a++, a++ ); // no warning
+  A agg2( a++ + a, a++ ); // expected-warning {{unsequenced modification and 
access to 'a'}}
+
+  int arr1[]( a++, a++ ); // no warning
+  int arr2[]( a++ + a, a++ ); // expected-warning {{unsequenced modification 
and access to 'a'}}
+}

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


[clang] [clang] Sequence C++20 Parenthesized List Init (PR #83476)

2024-02-29 Thread Douglas Deslauriers via cfe-commits

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


[clang] [clang] Sequence C++20 Parenthesized List Init (PR #83476)

2024-02-29 Thread Richard Smith via cfe-commits

https://github.com/zygoloid commented:

Thanks!

[I'm not sure when I'll have time to circle back to this, so I'd be happy for 
someone else to finish the review and approve.]

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


[clang] [clang] Sequence C++20 Parenthesized List Init (PR #83476)

2024-02-29 Thread Richard Smith via cfe-commits

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


[clang] [clang] Sequence C++20 Parenthesized List Init (PR #83476)

2024-02-29 Thread Richard Smith via cfe-commits


@@ -17626,6 +17626,25 @@ class SequenceChecker : public 
ConstEvaluatedExprVisitor {
 for (unsigned I = 0; I < Elts.size(); ++I)
   Tree.merge(Elts[I]);
   }
+
+  void VisitCXXParenListInitExpr(const CXXParenListInitExpr *PLIE) {
+// C++20 parenthesized list initializations are sequenced. See C++20
+// [decl.init]p17.5 and [decl.init]p17.6.2.2

zygoloid wrote:

I think you mean `dcl.init.general`, not `decl.init` here, and the wording is 
in p16 not p17 in C++20 and the current working paper.
```suggestion
// [dcl.init.general]p16.5 and [dcl.init.general]p16.6.2.2.
```

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


[clang] [clang] Sequence C++20 Parenthesized List Init (PR #83476)

2024-02-29 Thread Richard Smith via cfe-commits


@@ -17626,6 +17626,25 @@ class SequenceChecker : public 
ConstEvaluatedExprVisitor {
 for (unsigned I = 0; I < Elts.size(); ++I)
   Tree.merge(Elts[I]);
   }
+
+  void VisitCXXParenListInitExpr(const CXXParenListInitExpr *PLIE) {
+// C++20 parenthesized list initializations are sequenced. See C++20
+// [decl.init]p17.5 and [decl.init]p17.6.2.2
+SmallVector Elts;
+SequenceTree::Seq Parent = Region;
+for (const Expr *E : PLIE->getInitExprs()) {
+  if (!E)
+continue;
+  Region = Tree.allocate(Parent);
+  Elts.push_back(Region);
+  Visit(E);
+}
+
+// Forget that the initializers are sequenced.
+Region = Parent;
+for (unsigned I = 0; I < Elts.size(); ++I)
+  Tree.merge(Elts[I]);
+  }

zygoloid wrote:

Is it feasible to factor out the common code between this and 
`VisitInitListExpr`? This looks nearly identical.

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


[clang] [clang] Sequence C++20 Parenthesized List Init (PR #83476)

2024-02-29 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Douglas Deslauriers (vapdrs)


Changes

Parenthesized list intializers are sequenced operations, see C++20 
[decl.init]p17.5 and [decl.init]p17.6.2.2 for more details.

Fixes #83474

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


2 Files Affected:

- (modified) clang/lib/Sema/SemaChecking.cpp (+19) 
- (added) clang/test/SemaCXX/warn-unsequenced-paren-list-init.cpp (+15) 


``diff
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 016e9830662042..eaa45378f8eb49 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -17626,6 +17626,25 @@ class SequenceChecker : public 
ConstEvaluatedExprVisitor {
 for (unsigned I = 0; I < Elts.size(); ++I)
   Tree.merge(Elts[I]);
   }
+
+  void VisitCXXParenListInitExpr(const CXXParenListInitExpr *PLIE) {
+// C++20 parenthesized list initializations are sequenced. See C++20
+// [decl.init]p17.5 and [decl.init]p17.6.2.2
+SmallVector Elts;
+SequenceTree::Seq Parent = Region;
+for (const Expr *E : PLIE->getInitExprs()) {
+  if (!E)
+continue;
+  Region = Tree.allocate(Parent);
+  Elts.push_back(Region);
+  Visit(E);
+}
+
+// Forget that the initializers are sequenced.
+Region = Parent;
+for (unsigned I = 0; I < Elts.size(); ++I)
+  Tree.merge(Elts[I]);
+  }
 };
 
 SequenceChecker::UsageInfo::UsageInfo() = default;
diff --git a/clang/test/SemaCXX/warn-unsequenced-paren-list-init.cpp 
b/clang/test/SemaCXX/warn-unsequenced-paren-list-init.cpp
new file mode 100644
index 00..5aeeb45f81e226
--- /dev/null
+++ b/clang/test/SemaCXX/warn-unsequenced-paren-list-init.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++20 -Wno-unused -Wunsequenced -verify 
%s
+
+struct A {
+  int x, y;
+};
+
+void test() {
+  int a = 0;
+
+  A agg1( a++, a++ ); // no warning
+  A agg2( a++ + a, a++ ); // expected-warning {{unsequenced modification and 
access to 'a'}}
+
+  int arr1[]( a++, a++ ); // no warning
+  int arr2[]( a++ + a, a++ ); // expected-warning {{unsequenced modification 
and access to 'a'}}
+}

``




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


[clang] [clang] Sequence C++20 Parenthesized List Init (PR #83476)

2024-02-29 Thread via cfe-commits

github-actions[bot] wrote:



Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this 
page.

If this is not working for you, it is probably because you do not have write
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using `@` followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from 
other developers.

If you have further questions, they may be answered by the [LLVM GitHub User 
Guide](https://llvm.org/docs/GitHub.html).

You can also ask questions in a comment on this PR, on the [LLVM 
Discord](https://discord.com/invite/xS7Z362) or on the 
[forums](https://discourse.llvm.org/).

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


[clang] [clang] Sequence C++20 Parenthesized List Init (PR #83476)

2024-02-29 Thread Douglas Deslauriers via cfe-commits

https://github.com/vapdrs created 
https://github.com/llvm/llvm-project/pull/83476

Parenthesized list intializers are sequenced operations, see C++20 
[decl.init]p17.5 and [decl.init]p17.6.2.2 for more details.

Fixes #83474

>From 82e371bdcde2da8336b8679fff941f8b0a0394ae Mon Sep 17 00:00:00 2001
From: Douglas Deslauriers 
Date: Thu, 29 Feb 2024 20:18:34 +
Subject: [PATCH] [clang] Sequence C++20 Parenthesized List Init

Parenthesized list intializers are sequenced operations, see C++20
[decl.init]p17.5 and [decl.init]p17.6.2.2 for more details.

Fixes #83474
---
 clang/lib/Sema/SemaChecking.cpp   | 19 +++
 .../warn-unsequenced-paren-list-init.cpp  | 15 +++
 2 files changed, 34 insertions(+)
 create mode 100644 clang/test/SemaCXX/warn-unsequenced-paren-list-init.cpp

diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 016e9830662042..eaa45378f8eb49 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -17626,6 +17626,25 @@ class SequenceChecker : public 
ConstEvaluatedExprVisitor {
 for (unsigned I = 0; I < Elts.size(); ++I)
   Tree.merge(Elts[I]);
   }
+
+  void VisitCXXParenListInitExpr(const CXXParenListInitExpr *PLIE) {
+// C++20 parenthesized list initializations are sequenced. See C++20
+// [decl.init]p17.5 and [decl.init]p17.6.2.2
+SmallVector Elts;
+SequenceTree::Seq Parent = Region;
+for (const Expr *E : PLIE->getInitExprs()) {
+  if (!E)
+continue;
+  Region = Tree.allocate(Parent);
+  Elts.push_back(Region);
+  Visit(E);
+}
+
+// Forget that the initializers are sequenced.
+Region = Parent;
+for (unsigned I = 0; I < Elts.size(); ++I)
+  Tree.merge(Elts[I]);
+  }
 };
 
 SequenceChecker::UsageInfo::UsageInfo() = default;
diff --git a/clang/test/SemaCXX/warn-unsequenced-paren-list-init.cpp 
b/clang/test/SemaCXX/warn-unsequenced-paren-list-init.cpp
new file mode 100644
index 00..5aeeb45f81e226
--- /dev/null
+++ b/clang/test/SemaCXX/warn-unsequenced-paren-list-init.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++20 -Wno-unused -Wunsequenced -verify 
%s
+
+struct A {
+  int x, y;
+};
+
+void test() {
+  int a = 0;
+
+  A agg1( a++, a++ ); // no warning
+  A agg2( a++ + a, a++ ); // expected-warning {{unsequenced modification and 
access to 'a'}}
+
+  int arr1[]( a++, a++ ); // no warning
+  int arr2[]( a++ + a, a++ ); // expected-warning {{unsequenced modification 
and access to 'a'}}
+}

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