Fix assertion failure when a field is given an address space.

llvm-svn: 176122
This commit is contained in:
Matt Arsenault 2013-02-26 21:16:00 +00:00
parent 7d36c01747
commit 376f72092c
4 changed files with 35 additions and 11 deletions

View File

@ -1729,6 +1729,8 @@ def err_as_qualified_auto_decl : Error<
"automatic variable qualified with an address space">;
def err_arg_with_address_space : Error<
"parameter may not be qualified with an address space">;
def err_field_with_address_space : Error<
"field may not be qualified with an address space">;
def err_attr_objc_ownership_redundant : Error<
"the type %0 is already explicitly ownership-qualified">;
def err_attribute_not_string : Error<

View File

@ -10144,6 +10144,12 @@ FieldDecl *Sema::HandleField(Scope *S, RecordDecl *Record,
}
}
// TR 18037 does not allow fields to be declared with address spaces.
if (T.getQualifiers().hasAddressSpace()) {
Diag(Loc, diag::err_field_with_address_space);
D.setInvalidType();
}
// OpenCL 1.2 spec, s6.9 r:
// The event type cannot be used to declare a structure or union field.
if (LangOpts.OpenCL && T->isEventT()) {
@ -10151,7 +10157,6 @@ FieldDecl *Sema::HandleField(Scope *S, RecordDecl *Record,
D.setInvalidType();
}
DiagnoseFunctionSpecifiers(D);
if (D.getDeclSpec().isThreadSpecified())

View File

@ -1611,9 +1611,9 @@ BuildFieldReferenceExpr(Sema &S, Expr *BaseExpr, bool IsArrow,
Qualifiers MemberQuals
= S.Context.getCanonicalType(MemberType).getQualifiers();
// TR 18037 does not allow fields to be declared with address spaces.
assert(!MemberQuals.hasAddressSpace());
Qualifiers Combined = BaseQuals + MemberQuals;
if (Combined != MemberQuals)
MemberType = S.Context.getQualifiedType(MemberType, Combined);

View File

@ -48,3 +48,20 @@ void test3(void) {
typedef void ft(void);
_AS1 ft qf; // expected-error {{function type may not be qualified with an address space}}
typedef _AS1 ft qft; // expected-error {{function type may not be qualified with an address space}}
typedef _AS2 int AS2Int;
struct HasASFields
{
_AS2 int as_field; // expected-error {{field may not be qualified with an address space}}
AS2Int typedef_as_field; // expected-error {{field may not be qualified with an address space}}
};
// Assertion failure was when the field was accessed
void access_as_field()
{
struct HasASFields x;
(void) bar.as_field;
}