forked from OSchip/llvm-project
Bug #:
Submitted by: Reviewed by: Fix a couple bugs in Sema::GetTypeForDeclarator(). Need to disallow: - void arrayOfFunctions[3]() - void arrayOfVoids[3] Need to talk to Chris about the return value... llvm-svn: 39365
This commit is contained in:
parent
cc3214299b
commit
06deba91d1
|
@ -15,6 +15,7 @@
|
|||
#include "clang/AST/ASTContext.h"
|
||||
#include "clang/AST/Decl.h"
|
||||
#include "clang/Parse/DeclSpec.h"
|
||||
#include "clang/Lex/IdentifierTable.h"
|
||||
using namespace llvm;
|
||||
using namespace clang;
|
||||
|
||||
|
@ -130,15 +131,23 @@ TypeRef Sema::GetTypeForDeclarator(Declarator &D, Scope *S) {
|
|||
else
|
||||
ASM = ArrayType::Normal;
|
||||
|
||||
Type *CanonicalT = T->getCanonicalType();
|
||||
|
||||
// If the element type is a struct or union that contains a variadic
|
||||
// array, reject it: C99 6.7.2.1p2.
|
||||
if (RecordType *EltTy = dyn_cast<RecordType>(T->getCanonicalType())) {
|
||||
if (RecordType *EltTy = dyn_cast<RecordType>(CanonicalT)) {
|
||||
if (EltTy->getDecl()->hasFlexibleArrayMember()) {
|
||||
std::string Name;
|
||||
T->getAsString(Name);
|
||||
Diag(DeclType.Loc, diag::err_flexible_array_in_array, Name);
|
||||
return TypeRef();
|
||||
}
|
||||
} else if (isa<FunctionType>(CanonicalT)) {// reject "void aryOfFunc[3]()"
|
||||
Diag(D.getIdentifierLoc(), diag::err_illegal_decl_array_of_functions,
|
||||
D.getIdentifier()->getName());
|
||||
} else if (CanonicalT->isVoidType()) { // reject "void aryOfVoids[3]"
|
||||
Diag(D.getIdentifierLoc(), diag::err_illegal_decl_array_of_voids,
|
||||
D.getIdentifier()->getName());
|
||||
}
|
||||
|
||||
T = Context.getArrayType(T, ASM, ATI.TypeQuals,
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include "clang/AST/ASTContext.h"
|
||||
#include "clang/AST/Decl.h"
|
||||
#include "clang/Parse/DeclSpec.h"
|
||||
#include "clang/Lex/IdentifierTable.h"
|
||||
using namespace llvm;
|
||||
using namespace clang;
|
||||
|
||||
|
@ -130,15 +131,23 @@ TypeRef Sema::GetTypeForDeclarator(Declarator &D, Scope *S) {
|
|||
else
|
||||
ASM = ArrayType::Normal;
|
||||
|
||||
Type *CanonicalT = T->getCanonicalType();
|
||||
|
||||
// If the element type is a struct or union that contains a variadic
|
||||
// array, reject it: C99 6.7.2.1p2.
|
||||
if (RecordType *EltTy = dyn_cast<RecordType>(T->getCanonicalType())) {
|
||||
if (RecordType *EltTy = dyn_cast<RecordType>(CanonicalT)) {
|
||||
if (EltTy->getDecl()->hasFlexibleArrayMember()) {
|
||||
std::string Name;
|
||||
T->getAsString(Name);
|
||||
Diag(DeclType.Loc, diag::err_flexible_array_in_array, Name);
|
||||
return TypeRef();
|
||||
}
|
||||
} else if (isa<FunctionType>(CanonicalT)) {// reject "void aryOfFunc[3]()"
|
||||
Diag(D.getIdentifierLoc(), diag::err_illegal_decl_array_of_functions,
|
||||
D.getIdentifier()->getName());
|
||||
} else if (CanonicalT->isVoidType()) { // reject "void aryOfVoids[3]"
|
||||
Diag(D.getIdentifierLoc(), diag::err_illegal_decl_array_of_voids,
|
||||
D.getIdentifier()->getName());
|
||||
}
|
||||
|
||||
T = Context.getArrayType(T, ASM, ATI.TypeQuals,
|
||||
|
|
|
@ -462,7 +462,11 @@ DIAG(ext_flexible_array_in_struct, EXTENSION,
|
|||
"'%s' may not be nested in a struct due to flexible array member")
|
||||
DIAG(err_flexible_array_in_array, ERROR,
|
||||
"'%s' may not be used as an array element due to flexible array member")
|
||||
|
||||
DIAG(err_illegal_decl_array_of_functions, ERROR,
|
||||
"'%s' declared as array of functions")
|
||||
DIAG(err_illegal_decl_array_of_voids, ERROR,
|
||||
"'%s' declared as array of voids")
|
||||
|
||||
// Expressions.
|
||||
DIAG(ext_sizeof_function_type, EXTENSION,
|
||||
"invalid application of 'sizeof' to a function type")
|
||||
|
|
Loading…
Reference in New Issue