TypePrinter should not omit the static keyword in array parameter declarators
authorHal Finkel <hfinkel@anl.gov>
Fri, 18 Jul 2014 23:19:20 +0000 (23:19 +0000)
committerHal Finkel <hfinkel@anl.gov>
Fri, 18 Jul 2014 23:19:20 +0000 (23:19 +0000)
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

clang/lib/AST/TypePrinter.cpp
clang/test/Sema/ast-print.c

index 8e2cea3..d357b32 100644 (file)
@@ -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 << '*';
 
index 2066e18..e40c4dd 100644 (file)
@@ -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];
+}
+