Skip to content

Commit 4157217

Browse files
authored
[clang] Add CodeGen tests for CWG 5xx issues (#84303)
This patch covers [CWG519](https://cplusplus.github.io/CWG/issues/519.html) "Null pointer preservation in `void*` conversions", [CWG571](https://cplusplus.github.io/CWG/issues/571.html) "References declared const".
1 parent 9e4f289 commit 4157217

File tree

4 files changed

+60
-19
lines changed

4 files changed

+60
-19
lines changed

clang/test/CXX/drs/dr519.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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 dr519 { // dr519: 2.7
10+
void f() {
11+
int *a = 0;
12+
void *v = a;
13+
bool c1 = v == static_cast<void *>(0);
14+
15+
void *w = 0;
16+
int *b = static_cast<int*>(w);
17+
bool c2 = b == static_cast<int *>(0);
18+
}
19+
} // namespace dr519
20+
21+
// We're checking that `null`s that were initially stored in `a` and `w`
22+
// are simply copied over all the way to respective comparisons with `null`.
23+
24+
// CHECK-LABEL: define {{.*}} void @dr519::f()()
25+
// CHECK: store ptr null, ptr [[A:%.+]],
26+
// CHECK-NEXT: [[TEMP_A:%.+]] = load ptr, ptr [[A]]
27+
// CHECK-NEXT: store ptr [[TEMP_A]], ptr [[V:%.+]],
28+
// CHECK-NEXT: [[TEMP_V:%.+]] = load ptr, ptr [[V]]
29+
// CHECK-NEXT: {{.+}} = icmp eq ptr [[TEMP_V]], null
30+
31+
// CHECK: store ptr null, ptr [[W:%.+]],
32+
// CHECK-NEXT: [[TEMP_W:%.+]] = load ptr, ptr [[W]]
33+
// CHECK-NEXT: store ptr [[TEMP_W]], ptr [[B:%.+]],
34+
// CHECK-NEXT: [[TEMP_B:%.+]] = load ptr, ptr [[B]]
35+
// CHECK-NEXT: {{.+}} = icmp eq ptr [[TEMP_B]], null
36+
// CHECK-LABEL: }

clang/test/CXX/drs/dr571.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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 dr571 { // dr571: 2.7
10+
typedef int &ir;
11+
int n;
12+
const ir r = n;
13+
// expected-warning@-1 {{'const' qualifier on reference type 'ir' (aka 'int &') has no effect}}
14+
ir r2 = n;
15+
}
16+
17+
// Entities have external linkage by default.
18+
19+
// CHECK: @dr571::r = constant ptr @dr571::n
20+
// CHECK: @dr571::r2 = constant ptr @dr571::n

clang/test/CXX/drs/dr5xx.cpp

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -141,15 +141,7 @@ namespace dr518 { // dr518: yes c++11
141141
// cxx98-error@-1 {{commas at the end of enumerator lists are a C++11 extension}}
142142
}
143143

144-
namespace dr519 { // dr519: yes
145-
// FIXME: Add a codegen test.
146-
#if __cplusplus >= 201103L
147-
#define fold(x) (__builtin_constant_p(x) ? (x) : (x))
148-
int test[fold((int*)(void*)0) ? -1 : 1];
149-
#undef fold
150-
#endif
151-
}
152-
144+
// dr519 is in dr519.cpp
153145
// dr520: na
154146

155147
// dr521: no
@@ -800,14 +792,7 @@ namespace dr570 { // dr570: dup 633
800792
// expected-note@#dr570-r {{previous definition is here}}
801793
}
802794

803-
namespace dr571 { // dr571 unknown
804-
// FIXME: Add a codegen test.
805-
typedef int &ir;
806-
int n;
807-
// FIXME: Test if this has internal linkage.
808-
const ir r = n;
809-
// expected-warning@-1 {{'const' qualifier on reference type 'ir' (aka 'int &') has no effect}}
810-
}
795+
// dr571 is in dr571.cpp
811796

812797
namespace dr572 { // dr572: yes
813798
enum E { a = 1, b = 2 };

clang/www/cxx_dr_status.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3154,7 +3154,7 @@ <h2 id="cxxdr">C++ defect report implementation status</h2>
31543154
<td><a href="https://cplusplus.github.io/CWG/issues/519.html">519</a></td>
31553155
<td>CD1</td>
31563156
<td>Null pointer preservation in <TT>void*</TT> conversions</td>
3157-
<td class="full" align="center">Yes</td>
3157+
<td class="full" align="center">Clang 2.7</td>
31583158
</tr>
31593159
<tr id="520">
31603160
<td><a href="https://cplusplus.github.io/CWG/issues/520.html">520</a></td>
@@ -3468,7 +3468,7 @@ <h2 id="cxxdr">C++ defect report implementation status</h2>
34683468
<td><a href="https://cplusplus.github.io/CWG/issues/571.html">571</a></td>
34693469
<td>CD2</td>
34703470
<td>References declared <TT>const</TT></td>
3471-
<td class="unknown" align="center">Unknown</td>
3471+
<td class="full" align="center">Clang 2.7</td>
34723472
</tr>
34733473
<tr id="572">
34743474
<td><a href="https://cplusplus.github.io/CWG/issues/572.html">572</a></td>

0 commit comments

Comments
 (0)