summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-10-26 23:22:23 +0000
committerChris Lattner <sabre@nondot.org>2008-10-26 23:22:23 +0000
commit46dcba6d2d2ef444a7119a27943ec2988076796a (patch)
tree7b8ce633369b055c97dfd76471e0036ac43c5536
parent8aafd35c79b6a2ecd6c7f52b8da55920de773ff8 (diff)
downloadbcm5719-llvm-46dcba6d2d2ef444a7119a27943ec2988076796a.tar.gz
bcm5719-llvm-46dcba6d2d2ef444a7119a27943ec2988076796a.zip
add some simple designator testcases. Reject things like this:
struct foo Y[10] = { [4] .arr [2] 4 // expected-error {{expected '=' or another designator}} }; because the "missing equals" extension only is valid if there is exactly one array designator. llvm-svn: 58215
-rw-r--r--clang/include/clang/Basic/DiagnosticKinds.def2
-rw-r--r--clang/include/clang/Parse/Designator.h8
-rw-r--r--clang/lib/Parse/ParseInit.cpp16
-rw-r--r--clang/test/Parser/designator.c17
4 files changed, 36 insertions, 7 deletions
diff --git a/clang/include/clang/Basic/DiagnosticKinds.def b/clang/include/clang/Basic/DiagnosticKinds.def
index 96a5d0053d8..9f59f947c69 100644
--- a/clang/include/clang/Basic/DiagnosticKinds.def
+++ b/clang/include/clang/Basic/DiagnosticKinds.def
@@ -311,6 +311,8 @@ DIAG(ext_gnu_array_range, EXTENSION,
"use of GNU array range extension")
DIAG(ext_gnu_missing_equal_designator, EXTENSION,
"use of GNU 'missing =' extension in designator")
+DIAG(err_expected_equal_designator, ERROR,
+ "expected '=' or another designator")
DIAG(ext_gnu_old_style_field_designator, EXTENSION,
"use of GNU old-style field designator extension")
DIAG(ext_gnu_case_range, EXTENSION,
diff --git a/clang/include/clang/Parse/Designator.h b/clang/include/clang/Parse/Designator.h
index 613eef7f07e..5abf70ddee0 100644
--- a/clang/include/clang/Parse/Designator.h
+++ b/clang/include/clang/Parse/Designator.h
@@ -151,7 +151,13 @@ public:
/// AddDesignator - Add a designator to the end of this list.
void AddDesignator(Designator D) {
Designators.push_back(D);
- }
+ }
+
+ unsigned getNumDesignators() const { return Designators.size(); }
+ const Designator &getDesignator(unsigned Idx) const {
+ assert(Idx < Designators.size());
+ return Designators[Idx];
+ }
/// ClearExprs - Null out any expression references, which prevents them from
/// being 'delete'd later.
diff --git a/clang/lib/Parse/ParseInit.cpp b/clang/lib/Parse/ParseInit.cpp
index ed30f64d939..f4d18fbb4cf 100644
--- a/clang/lib/Parse/ParseInit.cpp
+++ b/clang/lib/Parse/ParseInit.cpp
@@ -176,6 +176,7 @@ ParseInitializerWithPotentialDesignator(InitListDesignations &Designations,
// at least one designator, because the only case we can get into this method
// without a designator is when we have an objc message send. That case is
// handled and returned from above.
+ assert(Desig && "Designator didn't get created?");
// Handle a normal designator sequence end, which is an equal.
if (Tok.is(tok::equal)) {
@@ -184,15 +185,18 @@ ParseInitializerWithPotentialDesignator(InitListDesignations &Designations,
}
// We read some number of designators and found something that isn't an = or
- // an initializer. If we have exactly one array designator [TODO CHECK], this
+ // an initializer. If we have exactly one array designator, this
// is the GNU 'designation: array-designator' extension. Otherwise, it is a
// parse error.
- SourceLocation Loc = Tok.getLocation();
- ExprResult Init = ParseInitializer();
- if (Init.isInvalid) return Init;
+ if (Desig->getNumDesignators() == 1 &&
+ (Desig->getDesignator(0).isArrayDesignator() ||
+ Desig->getDesignator(0).isArrayRangeDesignator())) {
+ Diag(Tok, diag::ext_gnu_missing_equal_designator);
+ return ParseInitializer();
+ }
- Diag(Tok, diag::ext_gnu_missing_equal_designator);
- return Init;
+ Diag(Tok, diag::err_expected_equal_designator);
+ return true;
}
diff --git a/clang/test/Parser/designator.c b/clang/test/Parser/designator.c
new file mode 100644
index 00000000000..d17f1b50eca
--- /dev/null
+++ b/clang/test/Parser/designator.c
@@ -0,0 +1,17 @@
+// RUN: clang -fsyntax-only %s -verify -pedantic
+
+int X[] = {
+ [4]4, // expected-warning {{use of GNU 'missing =' extension in designator}}
+ [5] = 7
+};
+
+struct foo {
+ int arr[10];
+};
+
+struct foo Y[10] = {
+ [4] .arr [2] = 4,
+
+ // This is not the GNU array init designator extension.
+ [4] .arr [2] 4 // expected-error {{expected '=' or another designator}}
+};
OpenPOWER on IntegriCloud