[cfe-commits] r113909 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDecl.cpp test/Sema/MicrosoftExtensions.c

Francois Pichet pichet2000 at gmail.com
Tue Sep 14 17:14:08 PDT 2010


Author: fpichet
Date: Tue Sep 14 19:14:08 2010
New Revision: 113909

URL: http://llvm.org/viewvc/llvm-project?rev=113909&view=rev
Log:
Microsoft's flexible array rules relaxation:
   - in union
   - as the only element of a struct/class.

Added:
    cfe/trunk/test/Sema/MicrosoftExtensions.c
Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaDecl.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=113909&r1=113908&r2=113909&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Sep 14 19:14:08 2010
@@ -1965,6 +1965,13 @@
   "%0 may not be used as an array element due to flexible array member">;
 def err_flexible_array_init_nonempty : Error<
   "non-empty initialization of flexible array member inside subobject">;
+def ext_flexible_array_empty_aggregate : Extension<
+  "flexible array member %0 in otherwise empty %select{struct|class}1 "
+  "is a Microsoft extension">, InGroup<Microsoft>;
+def ext_flexible_array_union : Extension<
+  "flexible array member %0 in a union is a Microsoft extension">,
+  InGroup<Microsoft>;
+
 def err_flexible_array_init_needs_braces : Error<
   "flexible array requires brace-enclosed initializer">;
 def err_illegal_decl_array_of_functions : Error<
@@ -2869,8 +2876,8 @@
 def err_anonymous_record_with_type : Error<
   "types cannot be declared in an anonymous %select{struct|union}0">;
 def ext_anonymous_record_with_type : Extension<
-  "types declared in an anonymous %select{struct|union}0 are a Microsoft extension">,
-  InGroup<Microsoft>;
+  "types declared in an anonymous %select{struct|union}0 are a Microsoft "
+  "extension">, InGroup<Microsoft>;
 def err_anonymous_record_with_function : Error<
   "functions cannot be declared in an anonymous %select{struct|union}0">;
 def err_anonymous_record_with_static : Error<

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=113909&r1=113908&r2=113909&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Sep 14 19:14:08 2010
@@ -6619,10 +6619,22 @@
       FD->setInvalidDecl();
       EnclosingDecl->setInvalidDecl();
       continue;
-    } else if (FDTy->isIncompleteArrayType() && i == NumFields - 1 &&
-               Record && !Record->isUnion()) {
+    } else if (FDTy->isIncompleteArrayType() && Record && 
+               ((i == NumFields - 1 && !Record->isUnion()) ||
+                (getLangOptions().Microsoft &&
+                 (i == NumFields - 1 || Record->isUnion())))) {
       // Flexible array member.
-      if (NumNamedMembers < 1) {
+      // Microsoft is more permissive regarding flexible array.
+      // It will accept flexible array in union and also
+	    // as the sole element of a struct/class.
+      if (getLangOptions().Microsoft) {
+        if (Record->isUnion()) 
+          Diag(FD->getLocation(), diag::ext_flexible_array_union)
+            << FD->getDeclName();
+        else if (NumFields == 1) 
+          Diag(FD->getLocation(), diag::ext_flexible_array_empty_aggregate)
+            << FD->getDeclName() << Record->getTagKind();
+      } else  if (NumNamedMembers < 1) {
         Diag(FD->getLocation(), diag::err_flexible_array_empty_struct)
           << FD->getDeclName();
         FD->setInvalidDecl();
@@ -6637,7 +6649,6 @@
         EnclosingDecl->setInvalidDecl();
         continue;
       }
-      
       // Okay, we have a legal flexible array member at the end of the struct.
       if (Record)
         Record->setHasFlexibleArrayMember(true);

Added: cfe/trunk/test/Sema/MicrosoftExtensions.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/MicrosoftExtensions.c?rev=113909&view=auto
==============================================================================
--- cfe/trunk/test/Sema/MicrosoftExtensions.c (added)
+++ cfe/trunk/test/Sema/MicrosoftExtensions.c Tue Sep 14 19:14:08 2010
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 %s -fsyntax-only -Wmicrosoft -verify -fms-extensions
+
+
+struct A
+{
+   int a[];  /* expected-warning {{flexible array member 'a' in otherwise empty struct is a Microsoft extension}} */
+};
+
+struct C {
+   int l;
+   union {
+       int c1[];   /* expected-warning {{flexible array member 'c1' in a union is a Microsoft extension}}  */
+       char c2[];  /* expected-warning {{flexible array member 'c2' in a union is a Microsoft extension}} */
+   };
+};
+
+
+struct D {
+   int l;
+   int D[];
+};





More information about the cfe-commits mailing list