2022-10-06 12:12:57 +02:00
|
|
|
// RUN: %clang_cc1 -emit-llvm -triple x86_64-apple-darwin10 -o - %s | FileCheck %s
|
2010-07-15 18:58:16 +00:00
|
|
|
|
|
|
|
// PR6024
|
|
|
|
extern int i;
|
|
|
|
|
2022-10-06 12:12:57 +02:00
|
|
|
// CHECK: define{{.*}} nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) ptr @_Z16lvalue_noop_castv() [[NUW:#[0-9]+]]
|
2010-07-15 18:58:16 +00:00
|
|
|
const int &lvalue_noop_cast() {
|
|
|
|
if (i == 0)
|
2022-10-06 12:12:57 +02:00
|
|
|
// CHECK: store i32 17, ptr
|
2010-07-15 18:58:16 +00:00
|
|
|
return (const int&)17;
|
|
|
|
else if (i == 1)
|
2022-10-06 12:12:57 +02:00
|
|
|
// CHECK: store i32 17, ptr
|
2010-07-15 18:58:16 +00:00
|
|
|
return static_cast<const int&>(17);
|
2022-10-06 12:12:57 +02:00
|
|
|
// CHECK: store i32 17, ptr
|
2010-07-15 18:58:16 +00:00
|
|
|
return 17;
|
|
|
|
}
|
|
|
|
|
2022-10-06 12:12:57 +02:00
|
|
|
// CHECK-LABEL: define{{.*}} nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) ptr @_Z20lvalue_integral_castv()
|
2010-07-15 18:58:16 +00:00
|
|
|
const short &lvalue_integral_cast() {
|
|
|
|
if (i == 0)
|
2022-10-06 12:12:57 +02:00
|
|
|
// CHECK: store i16 17, ptr
|
2010-07-15 18:58:16 +00:00
|
|
|
return (const short&)17;
|
|
|
|
else if (i == 1)
|
2022-10-06 12:12:57 +02:00
|
|
|
// CHECK: store i16 17, ptr
|
2010-07-15 18:58:16 +00:00
|
|
|
return static_cast<const short&>(17);
|
2022-10-06 12:12:57 +02:00
|
|
|
// CHECK: store i16 17, ptr
|
2010-07-15 18:58:16 +00:00
|
|
|
return 17;
|
|
|
|
}
|
|
|
|
|
2022-10-06 12:12:57 +02:00
|
|
|
// CHECK-LABEL: define{{.*}} nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) ptr @_Z29lvalue_floating_integral_castv()
|
2010-07-15 18:58:16 +00:00
|
|
|
const short &lvalue_floating_integral_cast() {
|
|
|
|
if (i == 0)
|
2022-10-06 12:12:57 +02:00
|
|
|
// CHECK: store i16 17, ptr
|
2010-07-15 18:58:16 +00:00
|
|
|
return (const short&)17.5;
|
|
|
|
else if (i == 1)
|
2022-10-06 12:12:57 +02:00
|
|
|
// CHECK: store i16 17, ptr
|
2010-07-15 18:58:16 +00:00
|
|
|
return static_cast<const short&>(17.5);
|
2022-10-06 12:12:57 +02:00
|
|
|
// CHECK: store i16 17, ptr
|
2010-07-15 18:58:16 +00:00
|
|
|
return 17.5;
|
|
|
|
}
|
|
|
|
|
2022-10-06 12:12:57 +02:00
|
|
|
// CHECK-LABEL: define{{.*}} nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) ptr @_Z29lvalue_integral_floating_castv()
|
2010-07-15 18:58:16 +00:00
|
|
|
const float &lvalue_integral_floating_cast() {
|
|
|
|
if (i == 0)
|
2022-10-06 12:12:57 +02:00
|
|
|
// CHECK: store float 1.700000e+{{0*}}1, ptr
|
2010-07-15 18:58:16 +00:00
|
|
|
return (const float&)17;
|
|
|
|
else if (i == 1)
|
2022-10-06 12:12:57 +02:00
|
|
|
// CHECK: store float 1.700000e+{{0*}}1, ptr
|
2010-07-15 18:58:16 +00:00
|
|
|
return static_cast<const float&>(17);
|
2022-10-06 12:12:57 +02:00
|
|
|
// CHECK: store float 1.700000e+{{0*}}1, ptr
|
2010-07-15 18:58:16 +00:00
|
|
|
return 17;
|
|
|
|
}
|
|
|
|
|
2022-10-06 12:12:57 +02:00
|
|
|
// CHECK-LABEL: define{{.*}} nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) ptr @_Z20lvalue_floating_castv()
|
2010-07-15 18:58:16 +00:00
|
|
|
const float &lvalue_floating_cast() {
|
|
|
|
if (i == 0)
|
2022-10-06 12:12:57 +02:00
|
|
|
// CHECK: store float 1.700000e+{{0*}}1, ptr
|
2010-07-15 18:58:16 +00:00
|
|
|
return (const float&)17.0;
|
|
|
|
else if (i == 1)
|
2022-10-06 12:12:57 +02:00
|
|
|
// CHECK: store float 1.700000e+{{0*}}1, ptr
|
2010-07-15 18:58:16 +00:00
|
|
|
return static_cast<const float&>(17.0);
|
2022-10-06 12:12:57 +02:00
|
|
|
// CHECK: store float 1.700000e+{{0*}}1, ptr
|
2010-07-15 18:58:16 +00:00
|
|
|
return 17.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int get_int();
|
|
|
|
|
2022-10-06 12:12:57 +02:00
|
|
|
// CHECK-LABEL: define{{.*}} nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) ptr @_Z24lvalue_integer_bool_castv()
|
2010-07-15 18:58:16 +00:00
|
|
|
const bool &lvalue_integer_bool_cast() {
|
|
|
|
if (i == 0)
|
2022-01-16 18:53:11 +09:00
|
|
|
// CHECK: call noundef i32 @_Z7get_intv()
|
2010-07-15 18:58:16 +00:00
|
|
|
// CHECK: store i8
|
|
|
|
return (const bool&)get_int();
|
|
|
|
else if (i == 1)
|
2022-01-16 18:53:11 +09:00
|
|
|
// CHECK: call noundef i32 @_Z7get_intv()
|
2010-07-15 18:58:16 +00:00
|
|
|
// CHECK: store i8
|
|
|
|
return static_cast<const bool&>(get_int());
|
2022-01-16 18:53:11 +09:00
|
|
|
// CHECK: call noundef i32 @_Z7get_intv()
|
2010-07-15 18:58:16 +00:00
|
|
|
// CHECK: store i8
|
|
|
|
return get_int();
|
|
|
|
}
|
|
|
|
|
|
|
|
float get_float();
|
|
|
|
|
2022-10-06 12:12:57 +02:00
|
|
|
// CHECK-LABEL: define{{.*}} nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) ptr @_Z25lvalue_floating_bool_castv()
|
2010-07-15 18:58:16 +00:00
|
|
|
const bool &lvalue_floating_bool_cast() {
|
|
|
|
if (i == 0)
|
2022-01-16 18:53:11 +09:00
|
|
|
// CHECK: call noundef float @_Z9get_floatv()
|
2010-07-15 18:58:16 +00:00
|
|
|
// CHECK: fcmp une float
|
|
|
|
// CHECK: store i8
|
|
|
|
return (const bool&)get_float();
|
|
|
|
else if (i == 1)
|
2022-01-16 18:53:11 +09:00
|
|
|
// CHECK: call noundef float @_Z9get_floatv()
|
2010-07-15 18:58:16 +00:00
|
|
|
// CHECK: fcmp une float
|
|
|
|
// CHECK: store i8
|
|
|
|
return static_cast<const bool&>(get_float());
|
2022-01-16 18:53:11 +09:00
|
|
|
// CHECK: call noundef float @_Z9get_floatv()
|
2010-07-15 18:58:16 +00:00
|
|
|
// CHECK: fcmp une float
|
|
|
|
// CHECK: store i8
|
|
|
|
return get_float();
|
|
|
|
}
|
|
|
|
|
|
|
|
struct X { };
|
|
|
|
typedef int X::*pm;
|
|
|
|
typedef int (X::*pmf)(int);
|
|
|
|
|
|
|
|
pm get_pointer_to_member_data();
|
|
|
|
pmf get_pointer_to_member_function();
|
|
|
|
|
2022-10-06 12:12:57 +02:00
|
|
|
// CHECK-LABEL: define{{.*}} nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) ptr @_Z26lvalue_ptrmem_to_bool_castv()
|
2010-07-15 18:58:16 +00:00
|
|
|
const bool &lvalue_ptrmem_to_bool_cast() {
|
|
|
|
if (i == 0)
|
|
|
|
// CHECK: call i64 @_Z26get_pointer_to_member_datav()
|
|
|
|
// CHECK: store i8
|
2022-10-06 12:12:57 +02:00
|
|
|
// CHECK: store ptr
|
2010-07-15 18:58:16 +00:00
|
|
|
return (const bool&)get_pointer_to_member_data();
|
|
|
|
else if (i == 1)
|
|
|
|
// CHECK: call i64 @_Z26get_pointer_to_member_datav()
|
|
|
|
// CHECK: store i8
|
2022-10-06 12:12:57 +02:00
|
|
|
// CHECK: store ptr
|
2010-07-15 18:58:16 +00:00
|
|
|
return static_cast<const bool&>(get_pointer_to_member_data());
|
|
|
|
// CHECK: call i64 @_Z26get_pointer_to_member_datav()
|
|
|
|
// CHECK: store i8
|
2022-10-06 12:12:57 +02:00
|
|
|
// CHECK: store ptr
|
2010-07-15 18:58:16 +00:00
|
|
|
return get_pointer_to_member_data();
|
|
|
|
}
|
|
|
|
|
2022-10-06 12:12:57 +02:00
|
|
|
// CHECK-LABEL: define{{.*}} nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) ptr @_Z27lvalue_ptrmem_to_bool_cast2v
|
2010-07-15 18:58:16 +00:00
|
|
|
const bool &lvalue_ptrmem_to_bool_cast2() {
|
|
|
|
if (i == 0)
|
|
|
|
// CHECK: {{call.*_Z30get_pointer_to_member_functionv}}
|
|
|
|
// CHECK: store i8
|
2022-10-06 12:12:57 +02:00
|
|
|
// CHECK: store ptr
|
2010-07-15 18:58:16 +00:00
|
|
|
return (const bool&)get_pointer_to_member_function();
|
|
|
|
else if (i == 1)
|
|
|
|
// CHECK: {{call.*_Z30get_pointer_to_member_functionv}}
|
|
|
|
// CHECK: store i8
|
2022-10-06 12:12:57 +02:00
|
|
|
// CHECK: store ptr
|
2010-07-15 18:58:16 +00:00
|
|
|
return static_cast<const bool&>(get_pointer_to_member_function());
|
|
|
|
// CHECK: {{call.*_Z30get_pointer_to_member_functionv}}
|
|
|
|
// CHECK: store i8
|
2022-10-06 12:12:57 +02:00
|
|
|
// CHECK: store ptr
|
2010-07-15 18:58:16 +00:00
|
|
|
return get_pointer_to_member_function();
|
|
|
|
}
|
|
|
|
|
|
|
|
_Complex double get_complex_double();
|
|
|
|
|
|
|
|
// CHECK: {{define.*_Z2f1v}}
|
|
|
|
const _Complex float &f1() {
|
|
|
|
if (i == 0)
|
|
|
|
// CHECK: {{call.*_Z18get_complex_doublev}}
|
|
|
|
// CHECK: fptrunc
|
|
|
|
// CHECK: fptrunc
|
|
|
|
// CHECK: store float
|
|
|
|
// CHECK: store float
|
|
|
|
return (const _Complex float&)get_complex_double();
|
|
|
|
else if (i == 1)
|
|
|
|
// CHECK: {{call.*_Z18get_complex_doublev}}
|
|
|
|
// CHECK: fptrunc
|
|
|
|
// CHECK: fptrunc
|
|
|
|
// CHECK: store float
|
|
|
|
// CHECK: store float
|
|
|
|
return static_cast<const _Complex float&>(get_complex_double());
|
|
|
|
// CHECK: {{call.*_Z18get_complex_doublev}}
|
|
|
|
// CHECK: fptrunc
|
|
|
|
// CHECK: fptrunc
|
|
|
|
// CHECK: store float
|
|
|
|
// CHECK: store float
|
|
|
|
return get_complex_double();
|
|
|
|
}
|
2011-08-09 00:37:14 +00:00
|
|
|
|
2022-10-06 12:12:57 +02:00
|
|
|
// CHECK-LABEL: define{{.*}} i32 @_Z7pr10592RKi(ptr
|
2011-08-09 00:37:14 +00:00
|
|
|
unsigned pr10592(const int &v) {
|
2022-10-06 12:12:57 +02:00
|
|
|
// CHECK: [[VADDR:%[a-zA-Z0-9.]+]] = alloca ptr
|
2011-08-09 00:37:14 +00:00
|
|
|
// CHECK-NEXT: [[REFTMP:%[a-zA-Z0-9.]+]] = alloca i32
|
2022-10-06 12:12:57 +02:00
|
|
|
// CHECK-NEXT: store ptr [[V:%[a-zA-Z0-9.]+]], ptr [[VADDR]]
|
|
|
|
// CHECK-NEXT: [[VADDR_1:%[a-zA-Z0-9.]+]] = load ptr, ptr [[VADDR]]
|
|
|
|
// CHECK-NEXT: [[VVAL:%[a-zA-Z0-9.]+]] = load i32, ptr [[VADDR_1]]
|
|
|
|
// CHECK-NEXT: store i32 [[VVAL]], ptr [[REFTMP]]
|
|
|
|
// CHECK-NEXT: [[VVAL_I:%[a-zA-Z0-9.]+]] = load i32, ptr [[REFTMP]]
|
2011-08-09 00:37:14 +00:00
|
|
|
// CHECK-NEXT: ret i32 [[VVAL_I]]
|
|
|
|
return static_cast<const unsigned &>(v);
|
|
|
|
}
|
2011-08-14 04:50:34 +00:00
|
|
|
|
|
|
|
namespace PR10650 {
|
|
|
|
struct Helper {
|
|
|
|
unsigned long long id();
|
|
|
|
};
|
|
|
|
unsigned long long test(Helper *obj) {
|
|
|
|
return static_cast<const unsigned long long&>(obj->id());
|
|
|
|
}
|
2020-12-30 20:45:56 -08:00
|
|
|
// CHECK-LABEL: define{{.*}} i64 @_ZN7PR106504testEPNS_6HelperE
|
2011-08-14 04:50:34 +00:00
|
|
|
// CHECK: store i64
|
|
|
|
}
|
2013-02-20 07:22:19 +00:00
|
|
|
|
2021-07-09 17:58:48 +02:00
|
|
|
// CHECK: attributes [[NUW]] = { mustprogress noinline nounwind{{.*}} }
|