2010-07-16 02:58:16 +08:00
|
|
|
// RUN: %clang_cc1 -emit-llvm -triple x86_64-apple-darwin10 -o - %s | FileCheck %s
|
|
|
|
|
|
|
|
// PR6024
|
|
|
|
extern int i;
|
|
|
|
|
2014-07-18 23:52:10 +08:00
|
|
|
// CHECK: define dereferenceable({{[0-9]+}}) i32* @_Z16lvalue_noop_castv() [[NUW:#[0-9]+]]
|
2010-07-16 02:58:16 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-07-18 23:52:10 +08:00
|
|
|
// CHECK-LABEL: define dereferenceable({{[0-9]+}}) i16* @_Z20lvalue_integral_castv()
|
2010-07-16 02:58:16 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-07-18 23:52:10 +08:00
|
|
|
// CHECK-LABEL: define dereferenceable({{[0-9]+}}) i16* @_Z29lvalue_floating_integral_castv()
|
2010-07-16 02:58:16 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-07-18 23:52:10 +08:00
|
|
|
// CHECK-LABEL: define dereferenceable({{[0-9]+}}) float* @_Z29lvalue_integral_floating_castv()
|
2010-07-16 02:58:16 +08:00
|
|
|
const float &lvalue_integral_floating_cast() {
|
|
|
|
if (i == 0)
|
2010-07-19 19:48:10 +08:00
|
|
|
// CHECK: store float 1.700000e+{{0*}}1, float*
|
2010-07-16 02:58:16 +08:00
|
|
|
return (const float&)17;
|
|
|
|
else if (i == 1)
|
2010-07-19 19:48:10 +08:00
|
|
|
// CHECK: store float 1.700000e+{{0*}}1, float*
|
2010-07-16 02:58:16 +08:00
|
|
|
return static_cast<const float&>(17);
|
2010-07-19 19:48:10 +08:00
|
|
|
// CHECK: store float 1.700000e+{{0*}}1, float*
|
2010-07-16 02:58:16 +08:00
|
|
|
return 17;
|
|
|
|
}
|
|
|
|
|
2014-07-18 23:52:10 +08:00
|
|
|
// CHECK-LABEL: define dereferenceable({{[0-9]+}}) float* @_Z20lvalue_floating_castv()
|
2010-07-16 02:58:16 +08:00
|
|
|
const float &lvalue_floating_cast() {
|
|
|
|
if (i == 0)
|
2010-07-19 19:48:10 +08:00
|
|
|
// CHECK: store float 1.700000e+{{0*}}1, float*
|
2010-07-16 02:58:16 +08:00
|
|
|
return (const float&)17.0;
|
|
|
|
else if (i == 1)
|
2010-07-19 19:48:10 +08:00
|
|
|
// CHECK: store float 1.700000e+{{0*}}1, float*
|
2010-07-16 02:58:16 +08:00
|
|
|
return static_cast<const float&>(17.0);
|
2010-07-19 19:48:10 +08:00
|
|
|
// CHECK: store float 1.700000e+{{0*}}1, float*
|
2010-07-16 02:58:16 +08:00
|
|
|
return 17.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int get_int();
|
|
|
|
|
2014-07-18 23:52:10 +08:00
|
|
|
// CHECK-LABEL: define dereferenceable({{[0-9]+}}) i8* @_Z24lvalue_integer_bool_castv()
|
2010-07-16 02:58:16 +08:00
|
|
|
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();
|
|
|
|
|
2014-07-18 23:52:10 +08:00
|
|
|
// CHECK-LABEL: define dereferenceable({{[0-9]+}}) i8* @_Z25lvalue_floating_bool_castv()
|
2010-07-16 02:58:16 +08:00
|
|
|
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();
|
|
|
|
|
2014-07-18 23:52:10 +08:00
|
|
|
// CHECK-LABEL: define dereferenceable({{[0-9]+}}) i8* @_Z26lvalue_ptrmem_to_bool_castv()
|
2010-07-16 02:58:16 +08:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2014-07-18 23:52:10 +08:00
|
|
|
// CHECK-LABEL: define dereferenceable({{[0-9]+}}) i8* @_Z27lvalue_ptrmem_to_bool_cast2v
|
2010-07-16 02:58:16 +08:00
|
|
|
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();
|
|
|
|
}
|
2011-08-09 08:37:14 +08:00
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define i32 @_Z7pr10592RKi(i32*
|
2011-08-09 08:37:14 +08:00
|
|
|
unsigned pr10592(const int &v) {
|
|
|
|
// CHECK: [[VADDR:%[a-zA-Z0-9.]+]] = alloca i32*
|
|
|
|
// CHECK-NEXT: [[REFTMP:%[a-zA-Z0-9.]+]] = alloca i32
|
|
|
|
// CHECK-NEXT: store i32* [[V:%[a-zA-Z0-9.]+]], i32** [[VADDR]]
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK-NEXT: [[VADDR_1:%[a-zA-Z0-9.]+]] = load i32*, i32** [[VADDR]]
|
|
|
|
// CHECK-NEXT: [[VVAL:%[a-zA-Z0-9.]+]] = load i32, i32* [[VADDR_1]]
|
2011-08-09 08:37:14 +08:00
|
|
|
// CHECK-NEXT: store i32 [[VVAL]], i32* [[REFTMP]]
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK-NEXT: [[VVAL_I:%[a-zA-Z0-9.]+]] = load i32, i32* [[REFTMP]]
|
2011-08-09 08:37:14 +08:00
|
|
|
// CHECK-NEXT: ret i32 [[VVAL_I]]
|
|
|
|
return static_cast<const unsigned &>(v);
|
|
|
|
}
|
2011-08-14 12:50:34 +08:00
|
|
|
|
|
|
|
namespace PR10650 {
|
|
|
|
struct Helper {
|
|
|
|
unsigned long long id();
|
|
|
|
};
|
|
|
|
unsigned long long test(Helper *obj) {
|
|
|
|
return static_cast<const unsigned long long&>(obj->id());
|
|
|
|
}
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define i64 @_ZN7PR106504testEPNS_6HelperE
|
2011-08-14 12:50:34 +08:00
|
|
|
// CHECK: store i64
|
|
|
|
}
|
2013-02-20 15:22:19 +08:00
|
|
|
|
Cleanup the handling of noinline function attributes, -fno-inline,
-fno-inline-functions, -O0, and optnone.
These were really, really tangled together:
- We used the noinline LLVM attribute for -fno-inline
- But not for -fno-inline-functions (breaking LTO)
- But we did use it for -finline-hint-functions (yay, LTO is happy!)
- But we didn't for -O0 (LTO is sad yet again...)
- We had weird structuring of CodeGenOpts with both an inlining
enumeration and a boolean. They interacted in weird ways and
needlessly.
- A *lot* of set smashing went on with setting these, and then got worse
when we considered optnone and other inlining-effecting attributes.
- A bunch of inline affecting attributes were managed in a completely
different place from -fno-inline.
- Even with -fno-inline we failed to put the LLVM noinline attribute
onto many generated function definitions because they didn't show up
as AST-level functions.
- If you passed -O0 but -finline-functions we would run the normal
inliner pass in LLVM despite it being in the O0 pipeline, which really
doesn't make much sense.
- Lastly, we used things like '-fno-inline' to manipulate the pass
pipeline which forced the pass pipeline to be much more
parameterizable than it really needs to be. Instead we can *just* use
the optimization level to select a pipeline and control the rest via
attributes.
Sadly, this causes a bunch of churn in tests because we don't run the
optimizer in the tests and check the contents of attribute sets. It
would be awesome if attribute sets were a bit more FileCheck friendly,
but oh well.
I think this is a significant improvement and should remove the semantic
need to change what inliner pass we run in order to comply with the
requested inlining semantics by relying completely on attributes. It
also cleans up tho optnone and related handling a bit.
One unfortunate aspect of this is that for generating alwaysinline
routines like those in OpenMP we end up removing noinline and then
adding alwaysinline. I tried a bunch of other approaches, but because we
recompute function attributes from scratch and don't have a declaration
here I couldn't find anything substantially cleaner than this.
Differential Revision: https://reviews.llvm.org/D28053
llvm-svn: 290398
2016-12-23 09:24:49 +08:00
|
|
|
// CHECK: attributes [[NUW]] = { noinline nounwind{{.*}} }
|