llvm-project/clang/test/CodeGenCXX/conditional-temporaries.cpp

56 lines
875 B
C++
Raw Normal View History

2010-02-05 01:06:52 +08:00
// RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-apple-darwin9 -O3 | FileCheck %s
2010-02-05 01:06:52 +08:00
namespace {
static int ctorcalls;
static int dtorcalls;
2010-02-05 01:06:52 +08:00
struct A {
A() : i(0) { ctorcalls++; }
~A() { dtorcalls++; }
int i;
friend const A& operator<<(const A& a, int n) {
return a;
}
};
2010-02-05 01:06:52 +08:00
void g(int) { }
void g(const A&) { }
2010-02-05 01:06:52 +08:00
void f1(bool b) {
g(b ? A().i : 0);
g(b || A().i);
g(b && A().i);
g(b ? A() << 1 : A() << 2);
2010-02-05 01:06:52 +08:00
}
2010-02-05 01:06:52 +08:00
struct Checker {
Checker() {
f1(true);
f1(false);
}
};
2010-02-05 01:06:52 +08:00
Checker c;
}
// CHECK-LABEL: define i32 @_Z12getCtorCallsv()
int getCtorCalls() {
2010-02-05 01:29:32 +08:00
// CHECK: ret i32 5
return ctorcalls;
}
// CHECK-LABEL: define i32 @_Z12getDtorCallsv()
int getDtorCalls() {
2010-02-05 01:29:32 +08:00
// CHECK: ret i32 5
return dtorcalls;
}
// CHECK-LABEL: define zeroext i1 @_Z7successv()
bool success() {
// CHECK: ret i1 true
return ctorcalls == dtorcalls;
}