[cfe-commits] r41443 - in /cfe/trunk: Sema/SemaType.cpp clang.xcodeproj/project.pbxproj test/Sema/array-constraint.c

Chris Lattner clattner at apple.com
Sun Aug 26 09:03:44 PDT 2007


> Fix bogus warnings (noticed by Chris) with array-constraints.c.

Ahh.. I didn't notice that the argument definition had an error.  The  
type was bogus, so the error recovery code (that you removed) changed  
it to be an array of int.

> Remove bogus type conversions in Sema::GetTypeForDeclarator(). This  
> commit
> only deals with the array types (DeclaratorCheck::Array), though the
> rest of this routine should be reviewed. Given the complexity of C  
> declarators,
> I don't want to change the entire routine now (will discuss with  
> Chris tomorrow).

Unfortunately, I think the "T = Context.IntTy;"'s should stay.   
Without these, we end up building an AST that has bogus array types.

Since the testcase isn't trying to test this situation, I'd suggest  
changing the function to:

struct s;
struct s* t (struct s z[]) {   // expected-error {{array has  
incomplete element type}}
   return 0;
}

What do you think?

-Chris

> ====================================================================== 
> ========
> --- cfe/trunk/Sema/SemaType.cpp (original)
> +++ cfe/trunk/Sema/SemaType.cpp Sun Aug 26 09:38:38 2007
> @@ -170,23 +170,19 @@
>        if (T->isIncompleteType()) {
>          Diag(D.getIdentifierLoc(),  
> diag::err_illegal_decl_array_incomplete_type,
>               T.getAsString());
> -        T = Context.IntTy;
>        } else if (T->isFunctionType()) {
>          Diag(D.getIdentifierLoc(),  
> diag::err_illegal_decl_array_of_functions,
>               D.getIdentifier()->getName());
> -        T = Context.getPointerType(T);
>        } else if (const ReferenceType *RT = T->getAsReferenceType()) {
>          // C++ 8.3.2p4: There shall be no ... arrays of  
> references ...
>          Diag(D.getIdentifierLoc(),  
> diag::err_illegal_decl_array_of_references,
>               D.getIdentifier()->getName());
> -        T = RT->getReferenceeType();
>        } else if (const RecordType *EltTy = T->getAsRecordType()) {
>          // If the element type is a struct or union that contains  
> a variadic
>          // array, reject it: C99 6.7.2.1p2.
>          if (EltTy->getDecl()->hasFlexibleArrayMember()) {
>            Diag(DeclType.Loc, diag::err_flexible_array_in_array,
>                 T.getAsString());
> -          T = Context.IntTy;
>          }
>        }
>        T = Context.getArrayType(T, ASM, ATI.TypeQuals,
>
> Modified: cfe/trunk/clang.xcodeproj/project.pbxproj
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/clang.xcodeproj/ 
> project.pbxproj?rev=41443&r1=41442&r2=41443&view=diff
>
> ====================================================================== 
> ========
> --- cfe/trunk/clang.xcodeproj/project.pbxproj (original)
> +++ cfe/trunk/clang.xcodeproj/project.pbxproj Sun Aug 26 09:38:38 2007
> @@ -210,7 +210,7 @@
>  		35260CA40C7F75C000D66CE9 /* ExprCXX.cpp */ = {isa =  
> PBXFileReference; fileEncoding = 4; lastKnownFileType =  
> sourcecode.cpp.cpp; name = ExprCXX.cpp; path = AST/ExprCXX.cpp;  
> sourceTree = "<group>"; };
>  		84D9A8870C1A57E100AC7ABC /* AttributeList.cpp */ = {isa =  
> PBXFileReference; fileEncoding = 30; lastKnownFileType =  
> sourcecode.cpp.cpp; name = AttributeList.cpp; path = Parse/ 
> AttributeList.cpp; sourceTree = "<group>"; };
>  		84D9A88B0C1A581300AC7ABC /* AttributeList.h */ = {isa =  
> PBXFileReference; fileEncoding = 30; lastKnownFileType =  
> sourcecode.c.h; name = AttributeList.h; path = clang/Parse/ 
> AttributeList.h; sourceTree = "<group>"; };
> -		8DD76F6C0486A84900D96B5E /* clang */ = {isa = PBXFileReference;  
> includeInIndex = 0; lastKnownFileType = "compiled.mach- 
> o.executable"; path = clang; sourceTree = BUILT_PRODUCTS_DIR; };
> +		8DD76F6C0486A84900D96B5E /* clang */ = {isa = PBXFileReference;  
> explicitFileType = "compiled.mach-o.executable"; includeInIndex =  
> 0; path = clang; sourceTree = BUILT_PRODUCTS_DIR; };
>  		DE01DA480B12ADA300AC22CE /* PPCallbacks.h */ = {isa =  
> PBXFileReference; fileEncoding = 30; lastKnownFileType =  
> sourcecode.c.h; path = PPCallbacks.h; sourceTree = "<group>"; };
>  		DE06756B0C051CFE00EBBFD8 /* ParseExprCXX.cpp */ = {isa =  
> PBXFileReference; fileEncoding = 30; lastKnownFileType =  
> sourcecode.cpp.cpp; name = ParseExprCXX.cpp; path = Parse/ 
> ParseExprCXX.cpp; sourceTree = "<group>"; };
>  		DE06B73D0A8307640050E87E /* LangOptions.h */ = {isa =  
> PBXFileReference; fileEncoding = 30; lastKnownFileType =  
> sourcecode.c.h; path = LangOptions.h; sourceTree = "<group>"; };
>
> Modified: cfe/trunk/test/Sema/array-constraint.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/array- 
> constraint.c?rev=41443&r1=41442&r2=41443&view=diff
>
> ====================================================================== 
> ========
> --- cfe/trunk/test/Sema/array-constraint.c (original)
> +++ cfe/trunk/test/Sema/array-constraint.c Sun Aug 26 09:38:38 2007
> @@ -1,4 +1,4 @@
> -// RUN: clang -parse-ast-check %s
> +// RUN: clang -parse-ast-check -pedantic %s
>
>  struct s;
>  struct s* t (struct s z[]) {   // expected-error {{array has  
> incomplete element type}}
> @@ -9,3 +9,19 @@
>    return l;
>  }
>
> +struct vari {
> +  int a;
> +  int b[];
> +};
> +
> +struct vari *func(struct vari a[]) { // expected-error {{'struct  
> vari' may not be used as an array element due to flexible array  
> member}}
> +  return a;
> +}
> +
> +int foo[](void);  // expected-error {{'foo' declared as array of  
> functions}}
> +
> +typedef int (*pfunc)(void);
> +
> +pfunc xx(int f[](void)) { // expected-error {{'f' declared as  
> array of functions}}
> +  return f;
> +}
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits




More information about the cfe-commits mailing list