Skip to content

Commit 7a0accc

Browse files
authored
[clang] Add some CodeGen tests for CWG 4xx issues (#83715)
This patch covers the following defect reports: [CWG438](https://cplusplus.github.io/CWG/issues/438.html) "Possible flaw in wording for multiple accesses to object between sequence points", [CWG439](https://cplusplus.github.io/CWG/issues/439.html) "Guarantees on casting pointer back to cv-qualified version of original type", [CWG441](https://cplusplus.github.io/CWG/issues/441.html) "Ordering of static reference initialization", [CWG462](https://cplusplus.github.io/CWG/issues/462.html) "Lifetime of temporaries bound to comma expressions", [CWG492](https://cplusplus.github.io/CWG/issues/492.html) "`typeid` constness inconsistent with example". [CWG475](https://cplusplus.github.io/CWG/issues/475.html) "When is `std::uncaught_exception()` true? (take 2)" requires a libc++abi test. As for [CWG454](https://cplusplus.github.io/CWG/issues/454.html) "When is a definition of a static data member required?", I don't feel confident in my understanding of it, so skipping over it.
1 parent bec7ad9 commit 7a0accc

File tree

7 files changed

+174
-11
lines changed

7 files changed

+174
-11
lines changed

clang/test/CXX/drs/dr438.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// 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
2+
// 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
3+
// 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
4+
// 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
5+
// 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
6+
// 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
7+
// 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
8+
9+
namespace dr438 { // dr438: 2.7
10+
11+
void f() {
12+
long A[2];
13+
A[0] = 0;
14+
A[A[0]] = 1;
15+
}
16+
17+
} // namespace dr438
18+
19+
// CHECK-LABEL: define {{.*}} void @dr438::f()()
20+
// CHECK: [[A:%.+]] = alloca [2 x i64]
21+
// CHECK: {{.+}} = getelementptr inbounds [2 x i64], ptr [[A]], i64 0, i64 0
22+
// CHECK: [[ARRAYIDX1:%.+]] = getelementptr inbounds [2 x i64], ptr [[A]], i64 0, i64 0
23+
// CHECK-NEXT: [[TEMPIDX:%.+]] = load i64, ptr [[ARRAYIDX1]]
24+
// CHECK-NEXT: [[ARRAYIDX2:%.+]] = getelementptr inbounds [2 x i64], ptr [[A]], i64 0, i64 [[TEMPIDX]]
25+
// CHECK-LABEL: }

clang/test/CXX/drs/dr439.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// 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
2+
// 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
3+
// 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
4+
// 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
5+
// 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
6+
// 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
7+
// 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
8+
9+
namespace dr439 { // dr439: 2.7
10+
11+
void f() {
12+
int* p1 = new int;
13+
const int* p2 = static_cast<const int*>(static_cast<void *>(p1));
14+
bool b = p1 == p2; // b will have the value true.
15+
}
16+
17+
} // namespace dr439
18+
19+
// We're checking that p2 was copied from p1, and then was carried over
20+
// to the comparison without change.
21+
22+
// CHECK-LABEL: define {{.*}} void @dr439::f()()
23+
// CHECK: [[P1:%.+]] = alloca ptr, align 8
24+
// CHECK-NEXT: [[P2:%.+]] = alloca ptr, align 8
25+
// CHECK: [[TEMP0:%.+]] = load ptr, ptr [[P1]]
26+
// CHECK-NEXT: store ptr [[TEMP0:%.+]], ptr [[P2]]
27+
// CHECK-NEXT: [[TEMP1:%.+]] = load ptr, ptr [[P1]]
28+
// CHECK-NEXT: [[TEMP2:%.+]] = load ptr, ptr [[P2]]
29+
// CHECK-NEXT: {{.*}} = icmp eq ptr [[TEMP1]], [[TEMP2]]
30+
// CHECK-LABEL: }

clang/test/CXX/drs/dr441.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// 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
2+
// 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
3+
// 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
4+
// 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
5+
// 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
6+
// 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
7+
// 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
8+
9+
namespace dr441 { // dr441: 2.7
10+
11+
struct A {
12+
A() {}
13+
};
14+
15+
A dynamic_init;
16+
int i;
17+
int& ir = i;
18+
int* ip = &i;
19+
20+
} // namespace dr441
21+
22+
// CHECK-DAG: @dr441::dynamic_init = global %"struct.dr441::A" zeroinitializer
23+
// CHECK-DAG: @dr441::i = global i32 0
24+
// CHECK-DAG: @dr441::ir = constant ptr @dr441::i
25+
// CHECK-DAG: @dr441::ip = global ptr @dr441::i
26+
// CHECK-DAG: @llvm.global_ctors = appending global [{{.+}}] [{ {{.+}} } { {{.+}}, ptr @_GLOBAL__sub_I_dr441.cpp, {{.+}} }]
27+
28+
// CHECK-LABEL: define {{.*}} void @__cxx_global_var_init()
29+
// CHECK-NEXT: entry:
30+
// CHECK-NEXT: call void @dr441::A::A()({{.*}} @dr441::dynamic_init)
31+
// CHECK-NEXT: ret void
32+
// CHECK-NEXT: }
33+
34+
// CHECK-LABEL: define {{.*}} void @_GLOBAL__sub_I_dr441.cpp()
35+
// CHECK-NEXT: entry:
36+
// CHECK-NEXT: call void @__cxx_global_var_init()
37+
// CHECK-NEXT: ret void
38+
// CHECK-NEXT: }

clang/test/CXX/drs/dr462.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// 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
2+
// 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
3+
// 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
4+
// 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
5+
// 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
6+
// 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
7+
// 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
8+
9+
#if __cplusplus == 199711L
10+
#define NOTHROW throw()
11+
#else
12+
#define NOTHROW noexcept(true)
13+
#endif
14+
15+
namespace dr462 { // dr462: 2.7
16+
17+
struct A {
18+
~A() NOTHROW {}
19+
};
20+
21+
extern void full_expr_fence() NOTHROW;
22+
23+
void f() {
24+
const A& r = (3, A());
25+
full_expr_fence();
26+
}
27+
28+
} // namespace dr462
29+
30+
// CHECK-LABEL: define {{.*}} void @dr462::f()()
31+
// CHECK: call void @dr462::full_expr_fence()()
32+
// CHECK: call void @dr462::A::~A()
33+
// CHECK-LABEL: }

clang/test/CXX/drs/dr492.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// 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
2+
// 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
3+
// 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
4+
// 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
5+
// 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
6+
// 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
7+
// 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
8+
9+
#if __cplusplus == 199711L
10+
#define NOTHROW throw()
11+
#else
12+
#define NOTHROW noexcept(true)
13+
#endif
14+
15+
namespace std {
16+
struct type_info {
17+
const char* name() const NOTHROW;
18+
};
19+
}
20+
21+
namespace dr492 { // dr492: 2.7
22+
23+
void f() {
24+
typeid(int).name();
25+
typeid(const int).name();
26+
typeid(volatile int).name();
27+
typeid(const volatile int).name();
28+
}
29+
30+
} // namespace dr492
31+
32+
// CHECK-LABEL: define {{.*}} void @dr492::f()()
33+
// CHECK: {{.*}} = call {{.*}} @std::type_info::name() const({{.*}} @typeinfo for int)
34+
// CHECK-NEXT: {{.*}} = call {{.*}} @std::type_info::name() const({{.*}} @typeinfo for int)
35+
// CHECK-NEXT: {{.*}} = call {{.*}} @std::type_info::name() const({{.*}} @typeinfo for int)
36+
// CHECK-NEXT: {{.*}} = call {{.*}} @std::type_info::name() const({{.*}} @typeinfo for int)
37+
// CHECK-LABEL: }

clang/test/CXX/drs/dr4xx.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -698,9 +698,9 @@ namespace dr437 { // dr437: sup 1308
698698
};
699699
}
700700

701-
// dr438 FIXME write a codegen test
702-
// dr439 FIXME write a codegen test
703-
// dr441 FIXME write a codegen test
701+
// dr438 is in dr438.cpp
702+
// dr439 is in dr439.cpp
703+
// dr441 is in dr441.cpp
704704
// dr442: sup 348
705705
// dr443: na
706706

@@ -943,7 +943,7 @@ namespace dr460 { // dr460: yes
943943
}
944944

945945
// dr461: na
946-
// dr462 FIXME write a codegen test
946+
// dr462 is in dr462.cpp
947947
// dr463: na
948948
// dr464: na
949949
// dr465: na
@@ -1089,7 +1089,7 @@ namespace dr474 { // dr474: 3.4
10891089
}
10901090
}
10911091

1092-
// dr475 FIXME write a codegen test
1092+
// dr475 FIXME write a libc++abi test
10931093

10941094
namespace dr477 { // dr477: 3.5
10951095
struct A {
@@ -1437,7 +1437,7 @@ namespace dr491 { // dr491: dup 413
14371437
// expected-error@-1 {{excess elements in array initializer}}
14381438
}
14391439

1440-
// dr492 FIXME write a codegen test
1440+
// dr492 is in dr492.cpp
14411441

14421442
namespace dr493 { // dr493: dup 976
14431443
struct X {

clang/www/cxx_dr_status.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2668,13 +2668,13 @@ <h2 id="cxxdr">C++ defect report implementation status</h2>
26682668
<td><a href="https://cplusplus.github.io/CWG/issues/438.html">438</a></td>
26692669
<td>CD2</td>
26702670
<td>Possible flaw in wording for multiple accesses to object between sequence points</td>
2671-
<td class="unknown" align="center">Unknown</td>
2671+
<td class="full" align="center">Clang 2.7</td>
26722672
</tr>
26732673
<tr id="439">
26742674
<td><a href="https://cplusplus.github.io/CWG/issues/439.html">439</a></td>
26752675
<td>CD1</td>
26762676
<td>Guarantees on casting pointer back to cv-qualified version of original type</td>
2677-
<td class="unknown" align="center">Unknown</td>
2677+
<td class="full" align="center">Clang 2.7</td>
26782678
</tr>
26792679
<tr id="440">
26802680
<td><a href="https://cplusplus.github.io/CWG/issues/440.html">440</a></td>
@@ -2686,7 +2686,7 @@ <h2 id="cxxdr">C++ defect report implementation status</h2>
26862686
<td><a href="https://cplusplus.github.io/CWG/issues/441.html">441</a></td>
26872687
<td>CD1</td>
26882688
<td>Ordering of static reference initialization</td>
2689-
<td class="unknown" align="center">Unknown</td>
2689+
<td class="full" align="center">Clang 2.7</td>
26902690
</tr>
26912691
<tr id="442">
26922692
<td><a href="https://cplusplus.github.io/CWG/issues/442.html">442</a></td>
@@ -2812,7 +2812,7 @@ <h2 id="cxxdr">C++ defect report implementation status</h2>
28122812
<td><a href="https://cplusplus.github.io/CWG/issues/462.html">462</a></td>
28132813
<td>CD3</td>
28142814
<td>Lifetime of temporaries bound to comma expressions</td>
2815-
<td class="unknown" align="center">Unknown</td>
2815+
<td class="full" align="center">Clang 2.7</td>
28162816
</tr>
28172817
<tr id="463">
28182818
<td><a href="https://cplusplus.github.io/CWG/issues/463.html">463</a></td>
@@ -2992,7 +2992,7 @@ <h2 id="cxxdr">C++ defect report implementation status</h2>
29922992
<td><a href="https://cplusplus.github.io/CWG/issues/492.html">492</a></td>
29932993
<td>CD1</td>
29942994
<td><TT>typeid</TT> constness inconsistent with example</td>
2995-
<td class="unknown" align="center">Unknown</td>
2995+
<td class="full" align="center">Clang 2.7</td>
29962996
</tr>
29972997
<tr id="493">
29982998
<td><a href="https://cplusplus.github.io/CWG/issues/493.html">493</a></td>

0 commit comments

Comments
 (0)