unsigned TypeID = NumberedTypes.size();
- // We don't allow assigning names to void type
- if (Ty == Type::VoidTy)
- return Error(TypeLoc, "can't assign name to the void type");
-
// See if this type was previously referenced.
std::map<unsigned, std::pair<PATypeHolder, LocTy> >::iterator
FI = ForwardRefTypeIDs.find(TypeID);
ParseType(Ty))
return true;
- // We don't allow assigning names to void type
- if (Ty == Type::VoidTy)
- return Error(NameLoc, "can't assign name '" + Name + "' to the void type");
-
// Set the type name, checking for conflicts as we do so.
bool AlreadyExists = M->addTypeName(Name, Ty);
if (!AlreadyExists) return false;
return true;
}
- if (isa<FunctionType>(Ty) || Ty == Type::LabelTy || Ty == Type::VoidTy)
+ if (isa<FunctionType>(Ty) || Ty == Type::LabelTy)
return Error(TyLoc, "invalid type for global variable");
GlobalVariable *GV = 0;
//===----------------------------------------------------------------------===//
/// ParseType - Parse and resolve a full type.
-bool LLParser::ParseType(PATypeHolder &Result) {
+bool LLParser::ParseType(PATypeHolder &Result, bool AllowVoid) {
+ LocTy TypeLoc = Lex.getLoc();
if (ParseTypeRec(Result)) return true;
// Verify no unresolved uprefs.
if (!UpRefs.empty())
return Error(UpRefs.back().Loc, "invalid unresolved type up reference");
+ if (!AllowVoid && Result.get() == Type::VoidTy)
+ return Error(TypeLoc, "void type only allowed for function results");
+
return false;
}
if ((inType ? ParseTypeRec(ArgTy) : ParseType(ArgTy)) ||
ParseOptionalAttrs(Attrs, 0)) return true;
+ if (ArgTy == Type::VoidTy)
+ return Error(TypeLoc, "argument can not have void type");
+
if (Lex.getKind() == lltok::LocalVar ||
Lex.getKind() == lltok::StringConstant) { // FIXME: REMOVE IN LLVM 3.0
Name = Lex.getStrVal();
// Otherwise must be an argument type.
TypeLoc = Lex.getLoc();
- if (ParseTypeRec(ArgTy) ||
+ if ((inType ? ParseTypeRec(ArgTy) : ParseType(ArgTy)) ||
ParseOptionalAttrs(Attrs, 0)) return true;
+ if (ArgTy == Type::VoidTy)
+ return Error(TypeLoc, "argument can not have void type");
+
if (Lex.getKind() == lltok::LocalVar ||
Lex.getKind() == lltok::StringConstant) { // FIXME: REMOVE IN LLVM 3.0
Name = Lex.getStrVal();
}
std::vector<PATypeHolder> ParamsList;
+ LocTy EltTyLoc = Lex.getLoc();
if (ParseTypeRec(Result)) return true;
ParamsList.push_back(Result);
+ if (Result == Type::VoidTy)
+ return Error(EltTyLoc, "struct element can not have void type");
+
while (EatIfPresent(lltok::comma)) {
+ EltTyLoc = Lex.getLoc();
if (ParseTypeRec(Result)) return true;
+
+ if (Result == Type::VoidTy)
+ return Error(EltTyLoc, "struct element can not have void type");
+
ParamsList.push_back(Result);
}
PATypeHolder EltTy(Type::VoidTy);
if (ParseTypeRec(EltTy)) return true;
+ if (EltTy == Type::VoidTy)
+ return Error(TypeLoc, "array and vector element type cannot be void");
+
if (ParseToken(isVector ? lltok::greater : lltok::rsquare,
"expected end of sequential type"))
return true;
ParseOptionalVisibility(Visibility) ||
ParseOptionalCallingConv(CC) ||
ParseOptionalAttrs(RetAttrs, 1) ||
- ParseType(RetType, RetTypeLoc))
+ ParseType(RetType, RetTypeLoc, true /*void allowed*/))
return true;
// Verify that the linkage is ok.
AttrListPtr PAL = AttrListPtr::get(Attrs.begin(), Attrs.end());
+ if (PAL.paramHasAttr(1, Attribute::StructRet) &&
+ RetType != Type::VoidTy)
+ return Error(RetTypeLoc, "functions with 'sret' argument must return void");
+
const FunctionType *FT = FunctionType::get(RetType, ParamTypeList, isVarArg);
const PointerType *PFT = PointerType::getUnqual(FT);
bool LLParser::ParseRet(Instruction *&Inst, BasicBlock *BB,
PerFunctionState &PFS) {
PATypeHolder Ty(Type::VoidTy);
- if (ParseType(Ty)) return true;
+ if (ParseType(Ty, true /*void allowed*/)) return true;
if (Ty == Type::VoidTy) {
Inst = ReturnInst::Create();
Value *NormalBB, *UnwindBB;
if (ParseOptionalCallingConv(CC) ||
ParseOptionalAttrs(RetAttrs, 1) ||
- ParseType(RetType, RetTypeLoc) ||
+ ParseType(RetType, RetTypeLoc, true /*void allowed*/) ||
ParseValID(CalleeID) ||
ParseParameterList(ArgList, PFS) ||
ParseOptionalAttrs(FnAttrs, 2) ||
if ((isTail && ParseToken(lltok::kw_call, "expected 'tail call'")) ||
ParseOptionalCallingConv(CC) ||
ParseOptionalAttrs(RetAttrs, 1) ||
- ParseType(RetType, RetTypeLoc) ||
+ ParseType(RetType, RetTypeLoc, true /*void allowed*/) ||
ParseValID(CalleeID) ||
ParseParameterList(ArgList, PFS) ||
ParseOptionalAttrs(FnAttrs, 2))