aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Arsenault <Matthew.Arsenault@amd.com>2013-02-26 21:16:00 +0000
committerMatt Arsenault <Matthew.Arsenault@amd.com>2013-02-26 21:16:00 +0000
commit34b0adb52f1528fb03313bdd5fd73632c11fc678 (patch)
treea98ebe6caf5d6431dd4ab5d4bb3f3811ae0f39f1
parent5509f37aacf8a4d65f759554c9ec18adc1ac7b4e (diff)
Fix assertion failure when a field is given an address space.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176122 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Basic/DiagnosticSemaKinds.td2
-rw-r--r--lib/Sema/SemaDecl.cpp9
-rw-r--r--lib/Sema/SemaExprMember.cpp16
-rw-r--r--test/Sema/address_spaces.c19
4 files changed, 35 insertions, 11 deletions
diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td
index 13e52e0c6c..a17719df99 100644
--- a/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/include/clang/Basic/DiagnosticSemaKinds.td
@@ -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<
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 20c1b1015e..2416f39442 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -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);
diff --git a/lib/Sema/SemaExprMember.cpp b/lib/Sema/SemaExprMember.cpp
index 16f4a43bd7..7b016c6574 100644
--- a/lib/Sema/SemaExprMember.cpp
+++ b/lib/Sema/SemaExprMember.cpp
@@ -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 =
diff --git a/test/Sema/address_spaces.c b/test/Sema/address_spaces.c
index 24799daa9e..0ae3230a61 100644
--- a/test/Sema/address_spaces.c
+++ b/test/Sema/address_spaces.c
@@ -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;
+}
+