hanchenye-llvm-project/clang/test/PCH/exprs.c

99 lines
2.1 KiB
C
Raw Normal View History

// Test this without pch.
// RUN: %clang_cc1 -fblocks -include %S/exprs.h -fsyntax-only -verify %s
// Test with pch.
// RUN: %clang_cc1 -emit-pch -fblocks -o %t %S/exprs.h
// RUN: %clang_cc1 -fblocks -include-pch %t -fsyntax-only -verify %s
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;
int integer;
long long_integer;
double floating;
_Complex double floating_complex;
// DeclRefExpr
int_decl_ref *int_ptr1 = &integer;
enum_decl_ref *enum_ptr1 = &integer;
// IntegerLiteral
integer_literal *int_ptr2 = &integer;
long_literal *long_ptr1 = &long_integer;
// FloatingLiteral + ParenExpr
floating_literal *double_ptr = &floating;
// ImaginaryLiteral
imaginary_literal *cdouble_ptr = &floating_complex;
// StringLiteral
const char* printHello() {
return hello;
}
// CharacterLiteral
char_literal *int_ptr3 = &integer;
// 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;
// UnaryExprOrTypeTraitExpr
typeof(sizeof(float)) size_t_value;
typeof_sizeof *size_t_ptr = &size_t_value;
typeof_sizeof2 *size_t_ptr2 = &size_t_value;
// ArraySubscriptExpr
array_subscript *double_ptr1_5 = &floating;
// CallExpr
call_returning_double *double_ptr2 = &floating;
// MemberExpr
member_ref_double *double_ptr3 = &floating;
// BinaryOperator
add_result *int_ptr5 = &integer;
// CompoundAssignOperator
addeq_result *int_ptr6 = &integer;
add_result_with_typeinfo *int_typeinfo_ptr6;
// ConditionalOperator
conditional_operator *double_ptr4 = &floating;
// CStyleCastExpr
void_ptr vp1 = &integer;
// CompoundLiteral
struct S s;
compound_literal *sptr = &s;
// ExtVectorElementExpr
ext_vector_element *double_ptr5 = &floating;
// InitListExpr
double get_from_double_array(unsigned Idx) { return double_array[Idx]; }
/// DesignatedInitExpr
float get_from_designated(unsigned Idx) {
return designated_inits[2].y;
}
// TypesCompatibleExpr
types_compatible *int_ptr7 = &integer;
// ChooseExpr
choose_expr *int_ptr8 = &integer;
// GNUNullExpr FIXME: needs C++
//null_type null = __null;
// ShuffleVectorExpr
shuffle_expr *vec_ptr = &vec2;
// GenericSelectionExpr
generic_selection_expr *double_ptr6 = &floating;