[cfe-commits] r44190 - in /cfe/trunk: Sema/SemaExpr.cpp test/Sema/expr-address-of.c

Chris Lattner sabre at nondot.org
Fri Nov 16 09:46:48 PST 2007


Author: lattner
Date: Fri Nov 16 11:46:48 2007
New Revision: 44190

URL: http://llvm.org/viewvc/llvm-project?rev=44190&view=rev
Log:
Tighten up address-of checking, implementing test/Sema/expr-address-of.c.  
This fixes a bug reported by Seo Sanghyeon.

This was meant to be committed yesterday, but the commit failed.  doh.

Added:
    cfe/trunk/test/Sema/expr-address-of.c
Modified:
    cfe/trunk/Sema/SemaExpr.cpp

Modified: cfe/trunk/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaExpr.cpp?rev=44190&r1=44189&r2=44190&view=diff

==============================================================================
--- cfe/trunk/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/Sema/SemaExpr.cpp Fri Nov 16 11:46:48 2007
@@ -1520,15 +1520,21 @@
   case Stmt::DeclRefExprClass:
     return cast<DeclRefExpr>(e)->getDecl();
   case Stmt::MemberExprClass:
+    // Fields cannot be declared with a 'register' storage class.
+    // &X->f is always ok, even if X is declared register.
+    if (cast<MemberExpr>(e)->isArrow())
+      return 0;
     return getPrimaryDeclaration(cast<MemberExpr>(e)->getBase());
   case Stmt::ArraySubscriptExprClass:
+    // &X[4] and &4[X] is invalid if X is invalid.
     return getPrimaryDeclaration(cast<ArraySubscriptExpr>(e)->getBase());
-  case Stmt::CallExprClass:
-    return getPrimaryDeclaration(cast<CallExpr>(e)->getCallee());
   case Stmt::UnaryOperatorClass:
     return getPrimaryDeclaration(cast<UnaryOperator>(e)->getSubExpr());
   case Stmt::ParenExprClass:
     return getPrimaryDeclaration(cast<ParenExpr>(e)->getSubExpr());
+  case Stmt::ImplicitCastExprClass:
+    // &X[4] when X is an array, has an implicit cast from array to pointer.
+    return getPrimaryDeclaration(cast<ImplicitCastExpr>(e)->getSubExpr());
   default:
     return 0;
   }
@@ -1544,9 +1550,8 @@
   Expr::isLvalueResult lval = op->isLvalue();
   
   if (lval != Expr::LV_Valid) { // C99 6.5.3.2p1
-    if (dcl && isa<FunctionDecl>(dcl)) // allow function designators
-      ;  
-    else { // FIXME: emit more specific diag...
+    if (!dcl || !isa<FunctionDecl>(dcl)) {// allow function designators
+      // FIXME: emit more specific diag...
       Diag(OpLoc, diag::err_typecheck_invalid_lvalue_addrof, 
            op->getSourceRange());
       return QualType();

Added: cfe/trunk/test/Sema/expr-address-of.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/expr-address-of.c?rev=44190&view=auto

==============================================================================
--- cfe/trunk/test/Sema/expr-address-of.c (added)
+++ cfe/trunk/test/Sema/expr-address-of.c Fri Nov 16 11:46:48 2007
@@ -0,0 +1,15 @@
+// RUN: clang %s -verify -fsyntax-only
+struct entry { int value; };
+void add_one(int *p) { (*p)++; }
+
+void test() {
+ register struct entry *p;
+ add_one(&p->value);
+}
+
+void foo() {
+  register int x[10];
+  &x[10];              // expected-error {{address of register variable requested}}
+}
+
+





More information about the cfe-commits mailing list