[cfe-commits] r64491 - in /cfe/trunk: lib/Sema/SemaExpr.cpp test/Sema/exprs.c

Chris Lattner sabre at nondot.org
Fri Feb 13 14:08:30 PST 2009


Author: lattner
Date: Fri Feb 13 16:08:30 2009
New Revision: 64491

URL: http://llvm.org/viewvc/llvm-project?rev=64491&view=rev
Log:
If x is an invalid field decl, don't construct an expression for P->x, 
just silently return an error to avoid bogus diagnostics.

Modified:
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/test/Sema/exprs.c

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Fri Feb 13 16:08:30 2009
@@ -1571,6 +1571,12 @@
     } else
       MemberDecl = Result;
 
+    // If the decl being referenced had an error, return an error for this
+    // sub-expr without emitting another error, in order to avoid cascading
+    // error cases.
+    if (MemberDecl->isInvalidDecl())
+      return ExprError();
+
     if (FieldDecl *FD = dyn_cast<FieldDecl>(MemberDecl)) {
       // We may have found a field within an anonymous union or struct
       // (C++ [class.union]).
@@ -1623,6 +1629,12 @@
   // (*Obj).ivar.
   if (const ObjCInterfaceType *IFTy = BaseType->getAsObjCInterfaceType()) {
     if (ObjCIvarDecl *IV = IFTy->getDecl()->lookupInstanceVariable(&Member)) {
+      // If the decl being referenced had an error, return an error for this
+      // sub-expr without emitting another error, in order to avoid cascading
+      // error cases.
+      if (IV->isInvalidDecl())
+        return ExprError();
+      
       ObjCIvarRefExpr *MRef= new (Context) ObjCIvarRefExpr(IV, IV->getType(), 
                                                  MemberLoc, BaseExpr,
                                                  OpKind == tok::arrow);

Modified: cfe/trunk/test/Sema/exprs.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/exprs.c?rev=64491&r1=64490&r2=64491&view=diff

==============================================================================
--- cfe/trunk/test/Sema/exprs.c (original)
+++ cfe/trunk/test/Sema/exprs.c Fri Feb 13 16:08:30 2009
@@ -57,3 +57,10 @@
   return R;
 }
 
+// PR3562
+void test10(int n,...) {
+  struct S {
+    double          a[n];  // expected-error {{fields must have a constant size}}
+  }               s;
+  double x = s.a[0];  // should not get another error here.
+}





More information about the cfe-commits mailing list