aboutsummaryrefslogtreecommitdiff
path: root/clang
diff options
context:
space:
mode:
authorHal Finkel <hfinkel@anl.gov>2014-07-18 23:19:20 +0000
committerHal Finkel <hfinkel@anl.gov>2014-07-18 23:19:20 +0000
commitf3e0265ea03ebcecb3828bb4c8ce5e6016777aec (patch)
tree7fa0eecc12ec8710eb55dfe12f19ca96adbc5b87 /clang
parentac6b4efaab360171a5872f991913d1dc5a97e1ca (diff)
downloadllvm-f3e0265ea03ebcecb3828bb4c8ce5e6016777aec.zip
llvm-f3e0265ea03ebcecb3828bb4c8ce5e6016777aec.tar.gz
llvm-f3e0265ea03ebcecb3828bb4c8ce5e6016777aec.tar.bz2
TypePrinter should not omit the static keyword in array parameter declarators
In C99, an array parameter declarator might have the form: direct-declarator '[' 'static' type-qual-list[opt] assign-expr ']' and when the size of the array is a constant, don't omit the static keyword when printing the type. Also, in the VLA case, put a space after the static keyword (some assignment expression must follow it). llvm-svn: 213424
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/AST/TypePrinter.cpp9
-rw-r--r--clang/test/Sema/ast-print.c11
2 files changed, 18 insertions, 2 deletions
diff --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp
index 8e2cea3..d357b32 100644
--- a/clang/lib/AST/TypePrinter.cpp
+++ b/clang/lib/AST/TypePrinter.cpp
@@ -430,7 +430,12 @@ void TypePrinter::printConstantArrayBefore(const ConstantArrayType *T,
}
void TypePrinter::printConstantArrayAfter(const ConstantArrayType *T,
raw_ostream &OS) {
- OS << '[' << T->getSize().getZExtValue() << ']';
+ OS << '[';
+
+ if (T->getSizeModifier() == VariableArrayType::Static)
+ OS << "static ";
+
+ OS << T->getSize().getZExtValue() << ']';
printAfter(T->getElementType(), OS);
}
@@ -461,7 +466,7 @@ void TypePrinter::printVariableArrayAfter(const VariableArrayType *T,
}
if (T->getSizeModifier() == VariableArrayType::Static)
- OS << "static";
+ OS << "static ";
else if (T->getSizeModifier() == VariableArrayType::Star)
OS << '*';
diff --git a/clang/test/Sema/ast-print.c b/clang/test/Sema/ast-print.c
index 2066e18..e40c4dd2 100644
--- a/clang/test/Sema/ast-print.c
+++ b/clang/test/Sema/ast-print.c
@@ -18,3 +18,14 @@ int foo(const struct blah *b) {
// CHECK: return b->b;
return b->b;
}
+
+int arr(int a[static 3]) {
+ // CHECK: int a[static 3]
+ return a[2];
+}
+
+int varr(int n, int a[static n]) {
+ // CHECK: int a[static n]
+ return a[2];
+}
+