summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/Sema/SemaExpr.cpp20
-rw-r--r--clang/include/clang/Basic/DiagnosticKinds.def4
-rw-r--r--clang/test/Sema/expr-address-of.c15
3 files changed, 31 insertions, 8 deletions
diff --git a/clang/Sema/SemaExpr.cpp b/clang/Sema/SemaExpr.cpp
index 5b5b2d235ce..a82d0ad7e54 100644
--- a/clang/Sema/SemaExpr.cpp
+++ b/clang/Sema/SemaExpr.cpp
@@ -1718,19 +1718,29 @@ QualType Sema::CheckAddressOfOperand(Expr *op, SourceLocation OpLoc) {
op->getSourceRange());
return QualType();
}
- } else if (dcl) {
+ } else if (MemberExpr *MemExpr = dyn_cast<MemberExpr>(op)) { // C99 6.5.3.2p1
+ if (MemExpr->getMemberDecl()->isBitField()) {
+ Diag(OpLoc, diag::err_typecheck_address_of,
+ std::string("bit-field"), op->getSourceRange());
+ return QualType();
+ }
+ // Check for Apple extension for accessing vector components.
+ } else if (isa<ArraySubscriptExpr>(op) &&
+ cast<ArraySubscriptExpr>(op)->getBase()->getType()->isVectorType()) {
+ Diag(OpLoc, diag::err_typecheck_address_of,
+ std::string("vector"), op->getSourceRange());
+ return QualType();
+ } else if (dcl) { // C99 6.5.3.2p1
// We have an lvalue with a decl. Make sure the decl is not declared
// with the register storage-class specifier.
if (const VarDecl *vd = dyn_cast<VarDecl>(dcl)) {
if (vd->getStorageClass() == VarDecl::Register) {
- Diag(OpLoc, diag::err_typecheck_address_of_register,
- op->getSourceRange());
+ Diag(OpLoc, diag::err_typecheck_address_of,
+ std::string("register variable"), op->getSourceRange());
return QualType();
}
} else
assert(0 && "Unknown/unexpected decl type");
-
- // FIXME: add check for bitfields!
}
// If the operand has type "type", the result has type "pointer to type".
return Context.getPointerType(op->getType());
diff --git a/clang/include/clang/Basic/DiagnosticKinds.def b/clang/include/clang/Basic/DiagnosticKinds.def
index 2ebe72ed55f..8aff69e3eff 100644
--- a/clang/include/clang/Basic/DiagnosticKinds.def
+++ b/clang/include/clang/Basic/DiagnosticKinds.def
@@ -783,8 +783,8 @@ DIAG(err_typecheck_sclass_fscope, ERROR,
"illegal storage class on file-scoped variable")
DIAG(err_typecheck_sclass_func, ERROR,
"illegal storage class on function")
-DIAG(err_typecheck_address_of_register, ERROR,
- "address of register variable requested")
+DIAG(err_typecheck_address_of, ERROR,
+ "address of %0 requested")
DIAG(err_typecheck_invalid_lvalue_addrof, ERROR,
"address expression must be an lvalue or a function designator")
DIAG(err_typecheck_unary_expr, ERROR,
diff --git a/clang/test/Sema/expr-address-of.c b/clang/test/Sema/expr-address-of.c
index 5f46b630467..46ba5dae4dd 100644
--- a/clang/test/Sema/expr-address-of.c
+++ b/clang/test/Sema/expr-address-of.c
@@ -1,10 +1,18 @@
// RUN: clang %s -verify -fsyntax-only
-struct entry { int value; };
+struct xx { int bitf:1; };
+
+struct entry { struct xx *whatever;
+ int value;
+ int bitf:1; };
void add_one(int *p) { (*p)++; }
void test() {
register struct entry *p;
add_one(&p->value);
+ struct entry pvalue;
+ add_one(&p->bitf); // expected-error {{address of bit-field requested}}
+ add_one(&pvalue.bitf); // expected-error {{address of bit-field requested}}
+ add_one(&p->whatever->bitf); // expected-error {{address of bit-field requested}}
}
void foo() {
@@ -17,4 +25,9 @@ void foo() {
int *x3 = &y[10];
}
+void testVectorComponentAccess() {
+ typedef float v4sf __attribute__ ((vector_size (16)));
+ static v4sf q;
+ float* r = &q[0]; // expected-error {{address of vector requested}}
+}
OpenPOWER on IntegriCloud