]> granicus.if.org Git - clang/commitdiff
Fix http://llvm.org/bugs/show_bug.cgi?id=2103.
authorSteve Naroff <snaroff@apple.com>
Fri, 29 Feb 2008 23:30:25 +0000 (23:30 +0000)
committerSteve Naroff <snaroff@apple.com>
Fri, 29 Feb 2008 23:30:25 +0000 (23:30 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@47775 91177308-0d34-0410-b5e6-96231b3b80d8

Sema/SemaExpr.cpp
include/clang/Basic/DiagnosticKinds.def
test/Sema/expr-address-of.c

index 5b5b2d235ce5fa74fd52f8683ee7a52e332e538d..a82d0ad7e548ba223b295c322e5e92f1040e4b64 100644 (file)
@@ -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());
index 2ebe72ed55fc3ddfc08b3e5841d446c8dfef8ed4..8aff69e3effcb9e24ef37e669f849fb5d8fffa98 100644 (file)
@@ -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,
index 5f46b630467b96bc7c21174b60c326270e9be968..46ba5dae4dd2587b4f02a1838cdf0b949fafab9b 100644 (file)
@@ -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}}
+}