r213424 - TypePrinter should not omit the static keyword in array parameter declarators

Hal Finkel hfinkel at anl.gov
Fri Jul 18 16:19:20 PDT 2014


Author: hfinkel
Date: Fri Jul 18 18:19:20 2014
New Revision: 213424

URL: http://llvm.org/viewvc/llvm-project?rev=213424&view=rev
Log:
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).

Modified:
    cfe/trunk/lib/AST/TypePrinter.cpp
    cfe/trunk/test/Sema/ast-print.c

Modified: cfe/trunk/lib/AST/TypePrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/TypePrinter.cpp?rev=213424&r1=213423&r2=213424&view=diff
==============================================================================
--- cfe/trunk/lib/AST/TypePrinter.cpp (original)
+++ cfe/trunk/lib/AST/TypePrinter.cpp Fri Jul 18 18:19:20 2014
@@ -430,7 +430,12 @@ void TypePrinter::printConstantArrayBefo
 }
 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::printVariableArrayAfte
   }
 
   if (T->getSizeModifier() == VariableArrayType::Static)
-    OS << "static";
+    OS << "static ";
   else if (T->getSizeModifier() == VariableArrayType::Star)
     OS << '*';
 

Modified: cfe/trunk/test/Sema/ast-print.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/ast-print.c?rev=213424&r1=213423&r2=213424&view=diff
==============================================================================
--- cfe/trunk/test/Sema/ast-print.c (original)
+++ cfe/trunk/test/Sema/ast-print.c Fri Jul 18 18:19:20 2014
@@ -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];
+}
+





More information about the cfe-commits mailing list