[clang] [clang] Add test for CWG1807 (PR #77637)

Vlad Serebrennikov via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 12 08:12:44 PST 2024


https://github.com/Endilll updated https://github.com/llvm/llvm-project/pull/77637

>From 545ee4900e48b186e1c9fff93dc62a459ee19754 Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov <serebrennikov.vladislav at gmail.com>
Date: Wed, 10 Jan 2024 20:27:53 +0300
Subject: [PATCH 1/6] [clang] Add test for CWG1807

The test checks that objects in arrays are destructed in reverse order during stack unwinding.
---
 clang/test/CXX/drs/dr1807.cpp | 31 +++++++++++++++++++++++++++++++
 clang/www/cxx_dr_status.html  |  2 +-
 2 files changed, 32 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/CXX/drs/dr1807.cpp

diff --git a/clang/test/CXX/drs/dr1807.cpp b/clang/test/CXX/drs/dr1807.cpp
new file mode 100644
index 00000000000000..f599a36c8b2cbd
--- /dev/null
+++ b/clang/test/CXX/drs/dr1807.cpp
@@ -0,0 +1,31 @@
+// RUN: %clang_cc1 -std=c++98 %s -triple x86_64-linux-gnu -emit-llvm -o - -fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK,CXX98
+// RUN: %clang_cc1 -std=c++11 %s -triple x86_64-linux-gnu -emit-llvm -o - -fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK,SINCE-CXX11
+// RUN: %clang_cc1 -std=c++14 %s -triple x86_64-linux-gnu -emit-llvm -o - -fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK,SINCE-CXX11
+// RUN: %clang_cc1 -std=c++17 %s -triple x86_64-linux-gnu -emit-llvm -o - -fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK,SINCE-CXX11
+// RUN: %clang_cc1 -std=c++20 %s -triple x86_64-linux-gnu -emit-llvm -o - -fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK,SINCE-CXX11
+// RUN: %clang_cc1 -std=c++23 %s -triple x86_64-linux-gnu -emit-llvm -o - -fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK,SINCE-CXX11
+// RUN: %clang_cc1 -std=c++2c %s -triple x86_64-linux-gnu -emit-llvm -o - -fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK,SINCE-CXX11
+
+namespace dr1807 { // dr1807: 3.0
+struct S {
+  S() {}
+  ~S() {}
+};
+
+void f() {
+  try {
+    S s[3];
+  } catch (...) {}
+}
+}
+
+// CHECK:              invoke void @dr1807::S::S(){{.+}}
+// CHECK-NEXT:         {{.+}} unwind label %lpad
+
+// CHECK-LABEL:      lpad:
+// CHECK:              br {{.+}}, label {{.+}}, label %arraydestroy.body
+
+// CHECK-LABEL:      arraydestroy.body:
+// CHECK:              %arraydestroy.element = getelementptr {{.+}}, i64 -1
+// CXX98-NEXT:         invoke void @dr1807::S::~S(){{.*}}%arraydestroy.element
+// SINCE-CXX11-NEXT:   call void @dr1807::S::~S(){{.*}}%arraydestroy.element
diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index 2bded63d5cd41c..bea9d0f54c471e 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -10649,7 +10649,7 @@ <h2 id="cxxdr">C++ defect report implementation status</h2>
     <td><a href="https://cplusplus.github.io/CWG/issues/1807.html">1807</a></td>
     <td>CD4</td>
     <td>Order of destruction of array elements after an exception</td>
-    <td class="none" align="center">Unknown</td>
+    <td class="full" align="center">Clang 3.0</td>
   </tr>
   <tr class="open" id="1808">
     <td><a href="https://cplusplus.github.io/CWG/issues/1808.html">1808</a></td>

>From 81b5f521c4e8e77f39ef1b01612a7866c6de8440 Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov <serebrennikov.vladislav at gmail.com>
Date: Wed, 10 Jan 2024 21:57:30 +0300
Subject: [PATCH 2/6] Leave a comment in dr18xx.cpp

---
 clang/test/CXX/drs/dr18xx.cpp | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/test/CXX/drs/dr18xx.cpp b/clang/test/CXX/drs/dr18xx.cpp
index 1d76804907a5c1..e092c83ab4ce42 100644
--- a/clang/test/CXX/drs/dr18xx.cpp
+++ b/clang/test/CXX/drs/dr18xx.cpp
@@ -164,6 +164,8 @@ void A<double, U>::C<V>::f4() {
 }
 } // namespace dr1804
 
+// dr1807 is in separate file
+
 namespace dr1812 { // dr1812: no
                    // NB: dup 1710
 #if __cplusplus >= 201103L

>From 59ec23c9cdd4d4557c0b471331683d577add31d6 Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov <serebrennikov.vladislav at gmail.com>
Date: Wed, 10 Jan 2024 22:06:01 +0300
Subject: [PATCH 3/6] Eliminate the need for readers to guess how the file is
 named

---
 clang/test/CXX/drs/dr18xx.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/CXX/drs/dr18xx.cpp b/clang/test/CXX/drs/dr18xx.cpp
index e092c83ab4ce42..530122ccd1aab1 100644
--- a/clang/test/CXX/drs/dr18xx.cpp
+++ b/clang/test/CXX/drs/dr18xx.cpp
@@ -164,7 +164,7 @@ void A<double, U>::C<V>::f4() {
 }
 } // namespace dr1804
 
-// dr1807 is in separate file
+// dr1807 is in dr1807.cpp
 
 namespace dr1812 { // dr1812: no
                    // NB: dup 1710

>From 62f1fa6bb3c691dde2e903711634857de486e71e Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov <serebrennikov.vladislav at gmail.com>
Date: Wed, 10 Jan 2024 23:33:41 +0300
Subject: [PATCH 4/6] Simplify C++ part of the test

---
 clang/test/CXX/drs/dr1807.cpp | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/clang/test/CXX/drs/dr1807.cpp b/clang/test/CXX/drs/dr1807.cpp
index f599a36c8b2cbd..e654987b485c76 100644
--- a/clang/test/CXX/drs/dr1807.cpp
+++ b/clang/test/CXX/drs/dr1807.cpp
@@ -13,9 +13,7 @@ struct S {
 };
 
 void f() {
-  try {
-    S s[3];
-  } catch (...) {}
+  S s[3];
 }
 }
 

>From 95155829973bb1006bfc4bbc518fd208b9f06c5b Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov <serebrennikov.vladislav at gmail.com>
Date: Fri, 12 Jan 2024 14:01:32 +0300
Subject: [PATCH 5/6] Remove `-n` argument passed to llvm-cxxfilt

It doesn't make a difference, and I don't really understand what it does.
---
 clang/test/CXX/drs/dr1807.cpp | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/clang/test/CXX/drs/dr1807.cpp b/clang/test/CXX/drs/dr1807.cpp
index e654987b485c76..78940d93837141 100644
--- a/clang/test/CXX/drs/dr1807.cpp
+++ b/clang/test/CXX/drs/dr1807.cpp
@@ -1,10 +1,10 @@
-// RUN: %clang_cc1 -std=c++98 %s -triple x86_64-linux-gnu -emit-llvm -o - -fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK,CXX98
-// RUN: %clang_cc1 -std=c++11 %s -triple x86_64-linux-gnu -emit-llvm -o - -fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK,SINCE-CXX11
-// RUN: %clang_cc1 -std=c++14 %s -triple x86_64-linux-gnu -emit-llvm -o - -fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK,SINCE-CXX11
-// RUN: %clang_cc1 -std=c++17 %s -triple x86_64-linux-gnu -emit-llvm -o - -fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK,SINCE-CXX11
-// RUN: %clang_cc1 -std=c++20 %s -triple x86_64-linux-gnu -emit-llvm -o - -fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK,SINCE-CXX11
-// RUN: %clang_cc1 -std=c++23 %s -triple x86_64-linux-gnu -emit-llvm -o - -fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK,SINCE-CXX11
-// RUN: %clang_cc1 -std=c++2c %s -triple x86_64-linux-gnu -emit-llvm -o - -fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK,SINCE-CXX11
+// RUN: %clang_cc1 -std=c++98 %s -triple x86_64-linux-gnu -emit-llvm -o - -fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt | FileCheck %s --check-prefixes CHECK,CXX98
+// RUN: %clang_cc1 -std=c++11 %s -triple x86_64-linux-gnu -emit-llvm -o - -fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt | FileCheck %s --check-prefixes CHECK,SINCE-CXX11
+// RUN: %clang_cc1 -std=c++14 %s -triple x86_64-linux-gnu -emit-llvm -o - -fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt | FileCheck %s --check-prefixes CHECK,SINCE-CXX11
+// RUN: %clang_cc1 -std=c++17 %s -triple x86_64-linux-gnu -emit-llvm -o - -fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt | FileCheck %s --check-prefixes CHECK,SINCE-CXX11
+// RUN: %clang_cc1 -std=c++20 %s -triple x86_64-linux-gnu -emit-llvm -o - -fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt | FileCheck %s --check-prefixes CHECK,SINCE-CXX11
+// RUN: %clang_cc1 -std=c++23 %s -triple x86_64-linux-gnu -emit-llvm -o - -fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt | FileCheck %s --check-prefixes CHECK,SINCE-CXX11
+// RUN: %clang_cc1 -std=c++2c %s -triple x86_64-linux-gnu -emit-llvm -o - -fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt | FileCheck %s --check-prefixes CHECK,SINCE-CXX11
 
 namespace dr1807 { // dr1807: 3.0
 struct S {

>From 1e77acaf19152695ecdaf0624ddbeb555a548638 Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov <serebrennikov.vladislav at gmail.com>
Date: Fri, 12 Jan 2024 19:11:11 +0300
Subject: [PATCH 6/6] Replace some hard-coded strings with captures

Label names has to be hard-coded, as variables are not allowed in `CHECK-LABEL` directives.
---
 clang/test/CXX/drs/dr1807.cpp | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/clang/test/CXX/drs/dr1807.cpp b/clang/test/CXX/drs/dr1807.cpp
index 78940d93837141..d367be7cf9465f 100644
--- a/clang/test/CXX/drs/dr1807.cpp
+++ b/clang/test/CXX/drs/dr1807.cpp
@@ -17,13 +17,12 @@ void f() {
 }
 }
 
+// CHECK-LABEL:      define dso_local void @dr1807::f()
 // CHECK:              invoke void @dr1807::S::S(){{.+}}
 // CHECK-NEXT:         {{.+}} unwind label %lpad
-
 // CHECK-LABEL:      lpad:
 // CHECK:              br {{.+}}, label {{.+}}, label %arraydestroy.body
-
-// CHECK-LABEL:      arraydestroy.body:
-// CHECK:              %arraydestroy.element = getelementptr {{.+}}, i64 -1
-// CXX98-NEXT:         invoke void @dr1807::S::~S(){{.*}}%arraydestroy.element
-// SINCE-CXX11-NEXT:   call void @dr1807::S::~S(){{.*}}%arraydestroy.element
+// CHECK-LABEL:      arraydestroy.body:         
+// CHECK:              [[ARRAYDESTROY_ELEMENT:%.*]] = getelementptr {{.+}}, i64 -1
+// CXX98-NEXT:         invoke void @dr1807::S::~S(){{.*}}[[ARRAYDESTROY_ELEMENT]]
+// SINCE-CXX11-NEXT:   call void @dr1807::S::~S(){{.*}}[[ARRAYDESTROY_ELEMENT]]



More information about the cfe-commits mailing list