From: Steve Naroff Date: Fri, 29 Feb 2008 23:30:25 +0000 (+0000) Subject: Fix http://llvm.org/bugs/show_bug.cgi?id=2103. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bcb2b6112072b071aafb0a7a28f16239c6a006a5;p=clang Fix http://llvm.org/bugs/show_bug.cgi?id=2103. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@47775 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/Sema/SemaExpr.cpp b/Sema/SemaExpr.cpp index 5b5b2d235c..a82d0ad7e5 100644 --- a/Sema/SemaExpr.cpp +++ b/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(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(op) && + cast(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(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/include/clang/Basic/DiagnosticKinds.def b/include/clang/Basic/DiagnosticKinds.def index 2ebe72ed55..8aff69e3ef 100644 --- a/include/clang/Basic/DiagnosticKinds.def +++ b/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/test/Sema/expr-address-of.c b/test/Sema/expr-address-of.c index 5f46b63046..46ba5dae4d 100644 --- a/test/Sema/expr-address-of.c +++ b/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}} +}