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,12 +10157,11 @@ FieldDecl *Sema::HandleField(Scope *S, RecordDecl *Record,
D.setInvalidType();
}
DiagnoseFunctionSpecifiers(D);
if (D.getDeclSpec().isThreadSpecified())
Diag(D.getDeclSpec().getThreadSpecLoc(), diag::err_invalid_thread);
// Check to see if this name was declared as a member previously
NamedDecl *PrevDecl = 0;
LookupResult Previous(*this, II, Loc, LookupMemberName, ForRedeclaration);

View File

@ -1598,27 +1598,27 @@ BuildFieldReferenceExpr(Sema &S, Expr *BaseExpr, bool IsArrow,
} else {
QualType BaseType = BaseExpr->getType();
if (IsArrow) BaseType = BaseType->getAs<PointerType>()->getPointeeType();
Qualifiers BaseQuals = BaseType.getQualifiers();
// GC attributes are never picked up by members.
BaseQuals.removeObjCGCAttr();
// CVR attributes from the base are picked up by members,
// except that 'mutable' members don't pick up 'const'.
if (Field->isMutable()) BaseQuals.removeConst();
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);
}
S.UnusedPrivateFields.remove(Field);
ExprResult Base =

View File

@ -6,7 +6,7 @@
void bar(_AS2 int a); // expected-error {{parameter may not be qualified with an address space}}
void foo(_AS3 float *a,
void foo(_AS3 float *a,
_AS1 float b) // expected-error {{parameter may not be qualified with an address space}}
{
_AS2 *x;// expected-warning {{type specifier missing, defaults to 'int'}}
@ -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;
}