[cfe-commits] r58603 - in /cfe/trunk: include/clang/Parse/Designator.h lib/Parse/ParseInit.cpp test/Sema/init.c
Chris Lattner
sabre at nondot.org
Mon Nov 3 01:28:22 PST 2008
Author: lattner
Date: Mon Nov 3 03:28:22 2008
New Revision: 58603
URL: http://llvm.org/viewvc/llvm-project?rev=58603&view=rev
Log:
Fix PR3001: if we have an error parsing an initializer, make sure to remove
the designator corresponding to it, otherwise Sema and later parsing will
get confused.
Modified:
cfe/trunk/include/clang/Parse/Designator.h
cfe/trunk/lib/Parse/ParseInit.cpp
cfe/trunk/test/Sema/init.c
Modified: cfe/trunk/include/clang/Parse/Designator.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Designator.h?rev=58603&r1=58602&r2=58603&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Designator.h (original)
+++ cfe/trunk/include/clang/Parse/Designator.h Mon Nov 3 03:28:22 2008
@@ -220,6 +220,17 @@
return &Designations[i];
return 0;
}
+
+ /// EraseDesignation - If there is a designator for the specified initializer
+ /// index, remove it.
+ void EraseDesignation(unsigned Idx) {
+ Designation *D =const_cast<Designation*>(getDesignationForInitializer(Idx));
+ if (D == 0) return; // No designator.
+
+ D->FreeExprs(Actions);
+ unsigned SlotNo = D-&Designations[0];
+ Designations.erase(Designations.begin()+SlotNo);
+ }
};
Modified: cfe/trunk/lib/Parse/ParseInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseInit.cpp?rev=58603&r1=58602&r2=58603&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseInit.cpp (original)
+++ cfe/trunk/lib/Parse/ParseInit.cpp Mon Nov 3 03:28:22 2008
@@ -263,10 +263,18 @@
ExprResult SubElt;
if (!MayBeDesignationStart(Tok.getKind(), PP))
SubElt = ParseInitializer();
- else
+ else {
SubElt = ParseInitializerWithPotentialDesignator(InitExprDesignations,
InitExprs.size());
-
+
+ // If we had an erroneous initializer, and we had a potentially valid
+ // designator, make sure to remove the designator from
+ // InitExprDesignations, otherwise we'll end up with a designator with no
+ // making initializer.
+ if (SubElt.isInvalid)
+ InitExprDesignations.EraseDesignation(InitExprs.size());
+ }
+
// If we couldn't parse the subelement, bail out.
if (!SubElt.isInvalid) {
InitExprs.push_back(SubElt.Val);
Modified: cfe/trunk/test/Sema/init.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/init.c?rev=58603&r1=58602&r2=58603&view=diff
==============================================================================
--- cfe/trunk/test/Sema/init.c (original)
+++ cfe/trunk/test/Sema/init.c Mon Nov 3 03:28:22 2008
@@ -67,3 +67,10 @@
((int)(&((struct sym_reg *)0)->nc_gpreg)) & 0,
8 * ((int)(&((struct sym_reg *)0)->nc_gpreg))
};
+
+// PR3001
+struct s1 s2 = {
+ .a = sizeof(struct s3), // expected-error {{invalid application of 'sizeof'}}
+ .b = bogus // expected-error {{use of undeclared identifier 'bogus'}}
+}
+
More information about the cfe-commits
mailing list