diff options
author | dim <dim@FreeBSD.org> | 2010-09-17 15:54:40 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2010-09-17 15:54:40 +0000 |
commit | 36c49e3f258dced101949edabd72e9bc3f1dedc4 (patch) | |
tree | 0bbe07708f7571f8b5291f6d7b96c102b7c99dee /test/CodeGenCXX/reference-cast.cpp | |
parent | fc84956ac8b7cd244ef30e7a4d4d38a58dec5904 (diff) | |
download | FreeBSD-src-36c49e3f258dced101949edabd72e9bc3f1dedc4.zip FreeBSD-src-36c49e3f258dced101949edabd72e9bc3f1dedc4.tar.gz |
Vendor import of clang r114020 (from the release_28 branch):
http://llvm.org/svn/llvm-project/cfe/branches/release_28@114020
Approved by: rpaulo (mentor)
Diffstat (limited to 'test/CodeGenCXX/reference-cast.cpp')
-rw-r--r-- | test/CodeGenCXX/reference-cast.cpp | 170 |
1 files changed, 170 insertions, 0 deletions
diff --git a/test/CodeGenCXX/reference-cast.cpp b/test/CodeGenCXX/reference-cast.cpp new file mode 100644 index 0000000..585d1db --- /dev/null +++ b/test/CodeGenCXX/reference-cast.cpp @@ -0,0 +1,170 @@ +// RUN: %clang_cc1 -emit-llvm -triple x86_64-apple-darwin10 -o - %s | FileCheck %s + +// PR6024 +extern int i; + +// CHECK: define i32* @_Z16lvalue_noop_castv() nounwind +const int &lvalue_noop_cast() { + if (i == 0) + // CHECK: store i32 17, i32* + return (const int&)17; + else if (i == 1) + // CHECK: store i32 17, i32* + return static_cast<const int&>(17); + // CHECK: store i32 17, i32* + return 17; +} + +// CHECK: define i16* @_Z20lvalue_integral_castv() +const short &lvalue_integral_cast() { + if (i == 0) + // CHECK: store i16 17, i16* + return (const short&)17; + else if (i == 1) + // CHECK: store i16 17, i16* + return static_cast<const short&>(17); + // CHECK: store i16 17, i16* + return 17; +} + +// CHECK: define i16* @_Z29lvalue_floating_integral_castv() +const short &lvalue_floating_integral_cast() { + if (i == 0) + // CHECK: store i16 17, i16* + return (const short&)17.5; + else if (i == 1) + // CHECK: store i16 17, i16* + return static_cast<const short&>(17.5); + // CHECK: store i16 17, i16* + return 17.5; +} + +// CHECK: define float* @_Z29lvalue_integral_floating_castv() +const float &lvalue_integral_floating_cast() { + if (i == 0) + // CHECK: store float 1.700000e+{{0*}}1, float* + return (const float&)17; + else if (i == 1) + // CHECK: store float 1.700000e+{{0*}}1, float* + return static_cast<const float&>(17); + // CHECK: store float 1.700000e+{{0*}}1, float* + return 17; +} + +// CHECK: define float* @_Z20lvalue_floating_castv() +const float &lvalue_floating_cast() { + if (i == 0) + // CHECK: store float 1.700000e+{{0*}}1, float* + return (const float&)17.0; + else if (i == 1) + // CHECK: store float 1.700000e+{{0*}}1, float* + return static_cast<const float&>(17.0); + // CHECK: store float 1.700000e+{{0*}}1, float* + return 17.0; +} + +int get_int(); + +// CHECK: define i8* @_Z24lvalue_integer_bool_castv() +const bool &lvalue_integer_bool_cast() { + if (i == 0) + // CHECK: call i32 @_Z7get_intv() + // CHECK: store i8 + return (const bool&)get_int(); + else if (i == 1) + // CHECK: call i32 @_Z7get_intv() + // CHECK: store i8 + return static_cast<const bool&>(get_int()); + // CHECK: call i32 @_Z7get_intv() + // CHECK: store i8 + return get_int(); +} + +float get_float(); + +// CHECK: define i8* @_Z25lvalue_floating_bool_castv() +const bool &lvalue_floating_bool_cast() { + if (i == 0) + // CHECK: call float @_Z9get_floatv() + // CHECK: fcmp une float + // CHECK: store i8 + return (const bool&)get_float(); + else if (i == 1) + // CHECK: call float @_Z9get_floatv() + // CHECK: fcmp une float + // CHECK: store i8 + return static_cast<const bool&>(get_float()); + // CHECK: call float @_Z9get_floatv() + // 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(); + +// CHECK: define i8* @_Z26lvalue_ptrmem_to_bool_castv() +const bool &lvalue_ptrmem_to_bool_cast() { + if (i == 0) + // CHECK: call i64 @_Z26get_pointer_to_member_datav() + // CHECK: store i8 + // CHECK: store i8* + return (const bool&)get_pointer_to_member_data(); + else if (i == 1) + // CHECK: call i64 @_Z26get_pointer_to_member_datav() + // CHECK: store i8 + // CHECK: store i8* + return static_cast<const bool&>(get_pointer_to_member_data()); + // CHECK: call i64 @_Z26get_pointer_to_member_datav() + // CHECK: store i8 + // CHECK: store i8* + return get_pointer_to_member_data(); +} + +// CHECK: define i8* @_Z27lvalue_ptrmem_to_bool_cast2v +const bool &lvalue_ptrmem_to_bool_cast2() { + if (i == 0) + // CHECK: {{call.*_Z30get_pointer_to_member_functionv}} + // CHECK: store i8 + // CHECK: store i8* + return (const bool&)get_pointer_to_member_function(); + else if (i == 1) + // CHECK: {{call.*_Z30get_pointer_to_member_functionv}} + // CHECK: store i8 + // CHECK: store i8* + return static_cast<const bool&>(get_pointer_to_member_function()); + // CHECK: {{call.*_Z30get_pointer_to_member_functionv}} + // CHECK: store i8 + // CHECK: store i8* + 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(); +} |