2009-04-15 05:18:50 +08:00
|
|
|
// Header for PCH test exprs.c
|
|
|
|
|
|
|
|
// DeclRefExpr
|
|
|
|
int i = 17;
|
|
|
|
enum Enum { Enumerator = 18 };
|
|
|
|
typedef typeof(i) int_decl_ref;
|
|
|
|
typedef typeof(Enumerator) enum_decl_ref;
|
|
|
|
|
2009-04-15 05:55:33 +08:00
|
|
|
// IntegerLiteral
|
2009-04-15 05:18:50 +08:00
|
|
|
typedef typeof(17) integer_literal;
|
|
|
|
typedef typeof(17l) long_literal;
|
|
|
|
|
2009-04-15 08:25:59 +08:00
|
|
|
// FloatingLiteral and ParenExpr
|
2009-04-15 07:59:37 +08:00
|
|
|
typedef typeof((42.5)) floating_literal;
|
2009-04-15 05:55:33 +08:00
|
|
|
|
2009-04-16 06:19:53 +08:00
|
|
|
// ImaginaryLiteral
|
|
|
|
typedef typeof(17.0i) imaginary_literal;
|
|
|
|
|
2009-04-16 00:35:07 +08:00
|
|
|
// StringLiteral
|
|
|
|
const char *hello = "Hello" "PCH" "World";
|
|
|
|
|
2009-04-15 05:55:33 +08:00
|
|
|
// CharacterLiteral
|
2009-04-15 05:18:50 +08:00
|
|
|
typedef typeof('a') char_literal;
|
2009-04-15 05:55:33 +08:00
|
|
|
|
2009-04-15 23:58:59 +08:00
|
|
|
// UnaryOperator
|
|
|
|
typedef typeof(-Enumerator) negate_enum;
|
|
|
|
|
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
|
|
|
|
struct X {
|
|
|
|
int member;
|
|
|
|
};
|
|
|
|
struct Y {
|
|
|
|
struct X array[5];
|
|
|
|
};
|
|
|
|
struct Z {
|
|
|
|
struct Y y;
|
|
|
|
};
|
|
|
|
typedef typeof(__builtin_offsetof(struct Z, y.array[1 + 2].member))
|
|
|
|
offsetof_type;
|
|
|
|
|
2009-04-15 23:58:59 +08:00
|
|
|
// SizeOfAlignOfExpr
|
|
|
|
typedef typeof(sizeof(int)) typeof_sizeof;
|
|
|
|
typedef typeof(sizeof(Enumerator)) typeof_sizeof2;
|
|
|
|
|
2009-04-16 06:19:53 +08:00
|
|
|
// ArraySubscriptExpr
|
|
|
|
extern double values[];
|
|
|
|
typedef typeof(values[2]) array_subscript;
|
|
|
|
|
2009-04-16 01:43:59 +08:00
|
|
|
// CallExpr
|
|
|
|
double dplus(double x, double y);
|
|
|
|
double d0, d1;
|
|
|
|
typedef typeof((&dplus)(d0, d1)) call_returning_double;
|
|
|
|
|
|
|
|
// MemberExpr
|
|
|
|
struct S {
|
|
|
|
double x;
|
|
|
|
};
|
|
|
|
typedef typeof(((struct S*)0)->x) member_ref_double;
|
|
|
|
|
2009-04-15 08:25:59 +08:00
|
|
|
// BinaryOperator
|
|
|
|
typedef typeof(i + Enumerator) add_result;
|
|
|
|
|
2009-04-16 06:40:36 +08:00
|
|
|
// CompoundAssignOperator
|
|
|
|
typedef typeof(i += Enumerator) addeq_result;
|
|
|
|
|
|
|
|
// ConditionalOperator
|
|
|
|
typedef typeof(i? : d0) conditional_operator;
|
|
|
|
|
2009-04-15 08:25:59 +08:00
|
|
|
// CStyleCastExpr
|
|
|
|
typedef typeof((void *)0) void_ptr;
|
|
|
|
|
2009-04-16 10:33:48 +08:00
|
|
|
// CompoundLiteral
|
|
|
|
typedef typeof((struct S){.x = 3.5}) compound_literal;
|
|
|
|
|
2009-04-16 07:02:49 +08:00
|
|
|
// ExtVectorElementExpr
|
|
|
|
typedef __attribute__(( ext_vector_type(2) )) double double2;
|
2009-04-16 08:01:45 +08:00
|
|
|
extern double2 vec2, vec2b;
|
2009-04-16 07:02:49 +08:00
|
|
|
typedef typeof(vec2.x) ext_vector_element;
|
2009-04-16 07:33:31 +08:00
|
|
|
|
2009-04-16 08:55:48 +08:00
|
|
|
// InitListExpr
|
|
|
|
double double_array[3] = { 1.0, 2.0 };
|
|
|
|
|
|
|
|
// DesignatedInitExpr
|
|
|
|
struct {
|
|
|
|
int x;
|
|
|
|
float y;
|
|
|
|
} designated_inits[3] = { [0].y = 17, [2].x = 12.3, 3.5 };
|
|
|
|
|
2009-04-16 07:33:31 +08:00
|
|
|
// TypesCompatibleExpr
|
|
|
|
typedef typeof(__builtin_types_compatible_p(float, double)) types_compatible;
|
|
|
|
|
|
|
|
// ChooseExpr
|
|
|
|
typedef typeof(__builtin_choose_expr(17 > 19, d0, 1)) choose_expr;
|
|
|
|
|
|
|
|
// GNUNullExpr FIXME: needs C++
|
|
|
|
// typedef typeof(__null) null_type;
|
2009-04-16 08:01:45 +08:00
|
|
|
|
|
|
|
// ShuffleVectorExpr
|
|
|
|
typedef typeof(__builtin_shufflevector(vec2, vec2b, 2, 1)) shuffle_expr;
|