[cfe-commits] r70162 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/AST/Type.cpp lib/Sema/SemaType.cpp test/Sema/vla.c
Eli Friedman
eli.friedman at gmail.com
Sun Apr 26 14:57:51 PDT 2009
Author: efriedma
Date: Sun Apr 26 16:57:51 2009
New Revision: 70162
URL: http://llvm.org/viewvc/llvm-project?rev=70162&view=rev
Log:
Add a bit more handling for declarations like "int a[*]".
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/AST/Type.cpp
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/test/Sema/vla.c
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=70162&r1=70161&r2=70162&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Sun Apr 26 16:57:51 2009
@@ -891,6 +891,8 @@
"array has incomplete element type %0">;
def err_illegal_decl_array_of_references : Error<
"'%0' declared as array of references">;
+def err_array_star_outside_prototype : Error<
+ "star modifier used outside of function prototype">;
def err_illegal_decl_pointer_to_reference : Error<
"'%0' declared as a pointer to a reference">;
def err_illegal_decl_mempointer_to_void : Error<
Modified: cfe/trunk/lib/AST/Type.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Type.cpp?rev=70162&r1=70161&r2=70162&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Type.cpp (original)
+++ cfe/trunk/lib/AST/Type.cpp Sun Apr 26 16:57:51 2009
@@ -37,7 +37,8 @@
}
void VariableArrayType::Destroy(ASTContext& C) {
- SizeExpr->Destroy(C);
+ if (SizeExpr)
+ SizeExpr->Destroy(C);
this->~VariableArrayType();
C.Deallocate(this);
}
Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=70162&r1=70161&r2=70162&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Sun Apr 26 16:57:51 2009
@@ -500,7 +500,10 @@
}
llvm::APSInt ConstVal(32);
if (!ArraySize) {
- T = Context.getIncompleteArrayType(T, ASM, Quals);
+ if (ASM == ArrayType::Star)
+ T = Context.getVariableArrayType(T, 0, ASM, Quals);
+ else
+ T = Context.getIncompleteArrayType(T, ASM, Quals);
} else if (ArraySize->isValueDependent()) {
T = Context.getDependentSizedArrayType(T, ArraySize, ASM, Quals);
} else if (!ArraySize->isIntegerConstantExpr(ConstVal, Context) ||
@@ -687,6 +690,15 @@
ASM = ArrayType::Static;
else
ASM = ArrayType::Normal;
+ if (ASM == ArrayType::Star &&
+ D.getContext() != Declarator::PrototypeContext) {
+ // FIXME: This check isn't quite right: it allows star in prototypes
+ // for function definitions, and disallows some edge cases detailed
+ // in http://gcc.gnu.org/ml/gcc-patches/2009-02/msg00133.html
+ Diag(DeclType.Loc, diag::err_array_star_outside_prototype);
+ ASM = ArrayType::Normal;
+ D.setInvalidType(true);
+ }
T = BuildArrayType(T, ASM, ArraySize, ATI.TypeQuals, DeclType.Loc, Name);
break;
}
Modified: cfe/trunk/test/Sema/vla.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/vla.c?rev=70162&r1=70161&r2=70162&view=diff
==============================================================================
--- cfe/trunk/test/Sema/vla.c (original)
+++ cfe/trunk/test/Sema/vla.c Sun Apr 26 16:57:51 2009
@@ -43,3 +43,6 @@
// PR3663
static const unsigned array[((2 * (int)((((4) / 2) + 1.0/3.0) * (4) - 1e-8)) + 1)]; // expected-warning {{size of static array must be an integer constant expression}}
+
+int a[*]; // expected-error {{star modifier used outside of function prototype}}
+int f4(int a[*][*]);
More information about the cfe-commits
mailing list