From: Hal Finkel Date: Fri, 18 Jul 2014 23:19:20 +0000 (+0000) Subject: TypePrinter should not omit the static keyword in array parameter declarators X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=170c2ddea2a1ddcf6a087a57d3bd3ba50ab68b0e;p=clang 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). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@213424 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/TypePrinter.cpp b/lib/AST/TypePrinter.cpp index 8e2cea3f88..d357b3215a 100644 --- a/lib/AST/TypePrinter.cpp +++ b/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/test/Sema/ast-print.c b/test/Sema/ast-print.c index 2066e182c1..e40c4dd231 100644 --- a/test/Sema/ast-print.c +++ b/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]; +} +