[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / CXX / drs / cwg439.cpp
blobe409b803797fab2d3337d3e211520a2ff7d5ab62
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
9 namespace cwg439 { // cwg439: 2.7
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.
17 } // namespace cwg439
19 // We're checking that p2 was copied from p1, and then was carried over
20 // to the comparison without change.
22 // CHECK-LABEL: define {{.*}} void @cwg439::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: }