[cfe-commits] r104733 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDecl.cpp lib/Sema/SemaDeclCXX.cpp test/SemaCXX/flexible-array-test.cpp
Fariborz Jahanian
fjahanian at apple.com
Wed May 26 13:19:07 PDT 2010
Author: fjahanian
Date: Wed May 26 15:19:07 2010
New Revision: 104733
URL: http://llvm.org/viewvc/llvm-project?rev=104733&view=rev
Log:
Fixes misc. flexible array bugs in c++ (PR7029).
Added:
cfe/trunk/test/SemaCXX/flexible-array-test.cpp
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=104733&r1=104732&r2=104733&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed May 26 15:19:07 2010
@@ -1828,6 +1828,8 @@
def err_flexible_array_empty_struct : Error<
"flexible array %0 not allowed in otherwise empty struct">;
+def err_flexible_array_has_nonpod_type : Error<
+ "flexible array %0 must have a non-dependent, non-POD type">;
def ext_flexible_array_in_struct : Extension<
"%0 may not be nested in a struct due to flexible array member">;
def ext_flexible_array_in_array : Extension<
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=104733&r1=104732&r2=104733&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed May 26 15:19:07 2010
@@ -6136,6 +6136,15 @@
EnclosingDecl->setInvalidDecl();
continue;
}
+ if (!FD->getType()->isDependentType() &&
+ !Context.getBaseElementType(FD->getType())->isPODType()) {
+ Diag(FD->getLocation(), diag::err_flexible_array_has_nonpod_type)
+ << FD->getDeclName();
+ FD->setInvalidDecl();
+ EnclosingDecl->setInvalidDecl();
+ continue;
+ }
+
// Okay, we have a legal flexible array member at the end of the struct.
if (Record)
Record->setHasFlexibleArrayMember(true);
Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=104733&r1=104732&r2=104733&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Wed May 26 15:19:07 2010
@@ -1892,9 +1892,15 @@
// Fields.
for (CXXRecordDecl::field_iterator Field = ClassDecl->field_begin(),
- E = ClassDecl->field_end(); Field != E; ++Field)
+ E = ClassDecl->field_end(); Field != E; ++Field) {
+ if ((*Field)->getType()->isIncompleteArrayType()) {
+ assert(ClassDecl->hasFlexibleArrayMember() &&
+ "Incomplete array type is not valid");
+ continue;
+ }
if (CollectFieldInitializer(Info, *Field, *Field))
HadError = true;
+ }
NumInitializers = Info.AllToInit.size();
if (NumInitializers > 0) {
@@ -4577,6 +4583,11 @@
}
QualType FieldType = Field->getType().getNonReferenceType();
+ if (FieldType->isIncompleteArrayType()) {
+ assert(ClassDecl->hasFlexibleArrayMember() &&
+ "Incomplete array type is not valid");
+ continue;
+ }
// Build references to the field in the object we're copying from and to.
CXXScopeSpec SS; // Intentionally empty
Added: cfe/trunk/test/SemaCXX/flexible-array-test.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/flexible-array-test.cpp?rev=104733&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/flexible-array-test.cpp (added)
+++ cfe/trunk/test/SemaCXX/flexible-array-test.cpp Wed May 26 15:19:07 2010
@@ -0,0 +1,45 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// pr7029
+
+template <class Key, class T> struct QMap
+{
+ void insert(const Key &, const T &);
+ T v;
+};
+
+
+template <class Key, class T>
+void QMap<Key, T>::insert(const Key &, const T &avalue)
+{
+ v = avalue;
+}
+
+
+struct inotify_event
+{
+ int wd;
+
+ // clang doesn't like '[]':
+ // cannot initialize a parameter of type 'void *' with an rvalue of type 'char (*)[]'
+ char name [];
+};
+
+
+void foo()
+{
+ inotify_event event;
+ inotify_event* ptr = &event;
+ inotify_event event1 = *ptr;
+ *ptr = event;
+ QMap<int, inotify_event> eventForId;
+ eventForId.insert(ptr->wd, *ptr);
+}
+
+struct S {
+ virtual void foo();
+};
+
+struct X {
+ int blah;
+ S strings[]; // expected-error {{flexible array 'strings' must have a non-dependent, non-POD type}}
+};
More information about the cfe-commits
mailing list