[cfe-commits] r47233 - in /cfe/trunk: AST/Type.cpp test/Sema/typedef-variable-type.c

Eli Friedman eli.friedman at gmail.com
Sat Feb 16 16:59:12 PST 2008


Author: efriedma
Date: Sat Feb 16 18:59:11 2008
New Revision: 47233

URL: http://llvm.org/viewvc/llvm-project?rev=47233&view=rev
Log:
Implemnt isVariablyModifiedType correctly.


Added:
    cfe/trunk/test/Sema/typedef-variable-type.c
Modified:
    cfe/trunk/AST/Type.cpp

Modified: cfe/trunk/AST/Type.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/Type.cpp?rev=47233&r1=47232&r2=47233&view=diff

==============================================================================
--- cfe/trunk/AST/Type.cpp (original)
+++ cfe/trunk/AST/Type.cpp Sat Feb 16 18:59:11 2008
@@ -246,13 +246,29 @@
   return getDesugaredType()->getAsVariableArrayType();
 }
 
-/// isVariablyModifiedType (C99 6.7.5.2p2) - Return true for variable array
-/// types that have a non-constant expression. This does not include "[]".
+/// isVariablyModifiedType (C99 6.7.5p3) - Return true for variable length
+/// array types and types that contain variable array types in their
+/// declarator
 bool Type::isVariablyModifiedType() const {
-  if (const VariableArrayType *VAT = getAsVariableArrayType()) {
-    if (VAT->getSizeExpr())
-      return true;
-  }
+  // A VLA is a veriably modified type
+  if (getAsVariableArrayType())
+    return true;
+
+  // An array can contain a variably modified type
+  if (const ArrayType* AT = getAsArrayType())
+    return AT->getElementType()->isVariablyModifiedType();
+
+  // A pointer can point to a variably modified type
+  if (const PointerType* PT = getAsPointerType())
+    return PT->getPointeeType()->isVariablyModifiedType();
+
+  // A function can return a variably modified type
+  // This one isn't completely obvious, but it follows from the
+  // definition in C99 6.7.5p3. Because of this rule, it's
+  // illegal to declare a function returning a variably modified type.
+  if (const FunctionType* FT = getAsFunctionType())
+    return FT->getResultType()->isVariablyModifiedType();
+
   return false;
 }
 

Added: cfe/trunk/test/Sema/typedef-variable-type.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/typedef-variable-type.c?rev=47233&view=auto

==============================================================================
--- cfe/trunk/test/Sema/typedef-variable-type.c (added)
+++ cfe/trunk/test/Sema/typedef-variable-type.c Sat Feb 16 18:59:11 2008
@@ -0,0 +1,3 @@
+// RUN: clang %s -verify -fsyntax-only -pedantic
+
+typedef int (*a)[!.0]; // expected-error{{variable length array declared outside of any function}}





More information about the cfe-commits mailing list