2009-04-15 05:18:50 +08:00
|
|
|
// Test this without pch.
|
2009-12-16 04:14:24 +08:00
|
|
|
// RUN: %clang_cc1 -fblocks -include %S/exprs.h -fsyntax-only -verify %s
|
2009-04-15 05:18:50 +08:00
|
|
|
|
|
|
|
// Test with pch.
|
2009-12-16 04:14:24 +08:00
|
|
|
// RUN: %clang_cc1 -emit-pch -fblocks -o %t %S/exprs.h
|
|
|
|
// RUN: %clang_cc1 -fblocks -include-pch %t -fsyntax-only -verify %s
|
2009-04-15 05:18:50 +08:00
|
|
|
|
Completely reimplement __builtin_offsetof, based on a patch by Roberto
Amadini.
This change introduces a new expression node type, OffsetOfExpr, that
describes __builtin_offsetof. Previously, __builtin_offsetof was
implemented using a unary operator whose subexpression involved
various synthesized array-subscript and member-reference expressions,
which was ugly and made it very hard to instantiate as a
template. OffsetOfExpr represents the AST more faithfully, with proper
type source information and a more compact representation.
OffsetOfExpr also has support for dependent __builtin_offsetof
expressions; it can be value-dependent, but will never be
type-dependent (like sizeof or alignof). This commit introduces
template instantiation for __builtin_offsetof as well.
There are two major caveats to this patch:
1) CodeGen cannot handle the case where __builtin_offsetof is not a
constant expression, so it produces an error. So, to avoid
regressing in C, we retain the old UnaryOperator-based
__builtin_offsetof implementation in C while using the shiny new
OffsetOfExpr implementation in C++. The old implementation can go
away once we have proper CodeGen support for this case, which we
expect won't cause much trouble in C++.
2) __builtin_offsetof doesn't work well with non-POD class types,
particularly when the designated field is found within a base
class. I will address this in a subsequent patch.
Fixes PR5880 and a bunch of assertions when building Boost.Python
tests.
llvm-svn: 102542
2010-04-29 06:16:22 +08:00
|
|
|
__SIZE_TYPE__ size_type_value;
|
2009-04-15 05:18:50 +08:00
|
|
|
int integer;
|
|
|
|
long long_integer;
|
2009-04-15 05:55:33 +08:00
|
|
|
double floating;
|
2009-04-16 06:19:53 +08:00
|
|
|
_Complex double floating_complex;
|
2009-04-15 05:18:50 +08:00
|
|
|
|
|
|
|
// DeclRefExpr
|
|
|
|
int_decl_ref *int_ptr1 = &integer;
|
|
|
|
enum_decl_ref *enum_ptr1 = &integer;
|
2009-04-15 05:55:33 +08:00
|
|
|
|
|
|
|
// IntegerLiteral
|
2009-04-15 05:18:50 +08:00
|
|
|
integer_literal *int_ptr2 = &integer;
|
|
|
|
long_literal *long_ptr1 = &long_integer;
|
|
|
|
|
2009-04-15 08:25:59 +08:00
|
|
|
// FloatingLiteral + ParenExpr
|
2009-04-15 05:55:33 +08:00
|
|
|
floating_literal *double_ptr = &floating;
|
|
|
|
|
2009-04-16 06:19:53 +08:00
|
|
|
// ImaginaryLiteral
|
|
|
|
imaginary_literal *cdouble_ptr = &floating_complex;
|
|
|
|
|
2009-04-16 00:35:07 +08:00
|
|
|
// StringLiteral
|
|
|
|
const char* printHello() {
|
|
|
|
return hello;
|
|
|
|
}
|
|
|
|
|
2009-04-15 05:55:33 +08:00
|
|
|
// CharacterLiteral
|
2009-04-15 05:18:50 +08:00
|
|
|
char_literal *int_ptr3 = &integer;
|
2009-04-15 08:25:59 +08:00
|
|
|
|
2009-04-15 23:58:59 +08:00
|
|
|
// UnaryOperator
|
|
|
|
negate_enum *int_ptr4 = &integer;
|
|
|
|
|
Completely reimplement __builtin_offsetof, based on a patch by Roberto
Amadini.
This change introduces a new expression node type, OffsetOfExpr, that
describes __builtin_offsetof. Previously, __builtin_offsetof was
implemented using a unary operator whose subexpression involved
various synthesized array-subscript and member-reference expressions,
which was ugly and made it very hard to instantiate as a
template. OffsetOfExpr represents the AST more faithfully, with proper
type source information and a more compact representation.
OffsetOfExpr also has support for dependent __builtin_offsetof
expressions; it can be value-dependent, but will never be
type-dependent (like sizeof or alignof). This commit introduces
template instantiation for __builtin_offsetof as well.
There are two major caveats to this patch:
1) CodeGen cannot handle the case where __builtin_offsetof is not a
constant expression, so it produces an error. So, to avoid
regressing in C, we retain the old UnaryOperator-based
__builtin_offsetof implementation in C while using the shiny new
OffsetOfExpr implementation in C++. The old implementation can go
away once we have proper CodeGen support for this case, which we
expect won't cause much trouble in C++.
2) __builtin_offsetof doesn't work well with non-POD class types,
particularly when the designated field is found within a base
class. I will address this in a subsequent patch.
Fixes PR5880 and a bunch of assertions when building Boost.Python
tests.
llvm-svn: 102542
2010-04-29 06:16:22 +08:00
|
|
|
// OffsetOfExpr
|
|
|
|
offsetof_type *offsetof_ptr = &size_type_value;
|
|
|
|
|
2009-04-15 23:58:59 +08:00
|
|
|
// SizeOfAlignOfExpr
|
|
|
|
typeof(sizeof(float)) size_t_value;
|
|
|
|
typeof_sizeof *size_t_ptr = &size_t_value;
|
|
|
|
typeof_sizeof2 *size_t_ptr2 = &size_t_value;
|
|
|
|
|
2009-04-16 06:19:53 +08:00
|
|
|
// ArraySubscriptExpr
|
|
|
|
array_subscript *double_ptr1_5 = &floating;
|
|
|
|
|
2009-04-16 01:43:59 +08:00
|
|
|
// CallExpr
|
|
|
|
call_returning_double *double_ptr2 = &floating;
|
|
|
|
|
|
|
|
// MemberExpr
|
|
|
|
member_ref_double *double_ptr3 = &floating;
|
|
|
|
|
2009-04-15 08:25:59 +08:00
|
|
|
// BinaryOperator
|
2009-04-15 23:58:59 +08:00
|
|
|
add_result *int_ptr5 = &integer;
|
2009-04-15 08:25:59 +08:00
|
|
|
|
2009-04-16 06:40:36 +08:00
|
|
|
// CompoundAssignOperator
|
|
|
|
addeq_result *int_ptr6 = &integer;
|
|
|
|
|
2010-06-29 06:28:35 +08:00
|
|
|
add_result_with_typeinfo *int_typeinfo_ptr6;
|
|
|
|
|
2009-04-16 06:40:36 +08:00
|
|
|
// ConditionalOperator
|
|
|
|
conditional_operator *double_ptr4 = &floating;
|
|
|
|
|
2009-04-15 08:25:59 +08:00
|
|
|
// CStyleCastExpr
|
|
|
|
void_ptr vp1 = &integer;
|
2009-04-16 07:02:49 +08:00
|
|
|
|
2009-04-16 10:33:48 +08:00
|
|
|
// CompoundLiteral
|
|
|
|
struct S s;
|
|
|
|
compound_literal *sptr = &s;
|
|
|
|
|
2009-04-16 07:02:49 +08:00
|
|
|
// ExtVectorElementExpr
|
|
|
|
ext_vector_element *double_ptr5 = &floating;
|
2009-04-16 07:33:31 +08:00
|
|
|
|
2009-04-16 08:55:48 +08:00
|
|
|
// InitListExpr
|
|
|
|
double get_from_double_array(unsigned Idx) { return double_array[Idx]; }
|
|
|
|
|
|
|
|
/// DesignatedInitExpr
|
|
|
|
float get_from_designated(unsigned Idx) {
|
|
|
|
return designated_inits[2].y;
|
|
|
|
}
|
|
|
|
|
2009-04-16 07:33:31 +08:00
|
|
|
// TypesCompatibleExpr
|
|
|
|
types_compatible *int_ptr7 = &integer;
|
|
|
|
|
|
|
|
// ChooseExpr
|
|
|
|
choose_expr *int_ptr8 = &integer;
|
|
|
|
|
|
|
|
// GNUNullExpr FIXME: needs C++
|
|
|
|
//null_type null = __null;
|
2009-04-16 08:01:45 +08:00
|
|
|
|
|
|
|
// ShuffleVectorExpr
|
|
|
|
shuffle_expr *vec_ptr = &vec2;
|