[llvm-commits] [llvm] r66482 - in /llvm/branches/Apple/Dib: lib/AsmParser/LLParser.cpp lib/AsmParser/LLParser.h test/Assembler/2009-02-28-CastOpc.ll
Bill Wendling
isanbard at gmail.com
Mon Mar 9 15:20:17 PDT 2009
Author: void
Date: Mon Mar 9 17:20:16 2009
New Revision: 66482
URL: http://llvm.org/viewvc/llvm-project?rev=66482&view=rev
Log:
Pull in some updates for the asm parser to fix some bugs in Dib.
Added:
llvm/branches/Apple/Dib/test/Assembler/2009-02-28-CastOpc.ll
Modified:
llvm/branches/Apple/Dib/lib/AsmParser/LLParser.cpp
llvm/branches/Apple/Dib/lib/AsmParser/LLParser.h
Modified: llvm/branches/Apple/Dib/lib/AsmParser/LLParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/lib/AsmParser/LLParser.cpp?rev=66482&r1=66481&r2=66482&view=diff
==============================================================================
--- llvm/branches/Apple/Dib/lib/AsmParser/LLParser.cpp (original)
+++ llvm/branches/Apple/Dib/lib/AsmParser/LLParser.cpp Mon Mar 9 17:20:16 2009
@@ -231,10 +231,6 @@
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);
@@ -266,10 +262,6 @@
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;
@@ -466,7 +458,7 @@
}
if (isa<FunctionType>(Ty) || Ty == Type::LabelTy)
- return Error(TyLoc, "invald type for global variable");
+ return Error(TyLoc, "invalid type for global variable");
GlobalVariable *GV = 0;
@@ -856,13 +848,17 @@
//===----------------------------------------------------------------------===//
/// 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;
}
@@ -1119,6 +1115,9 @@
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();
@@ -1139,9 +1138,12 @@
// 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();
@@ -1212,11 +1214,20 @@
}
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);
}
@@ -1251,6 +1262,9 @@
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;
@@ -2058,7 +2072,7 @@
ParseOptionalVisibility(Visibility) ||
ParseOptionalCallingConv(CC) ||
ParseOptionalAttrs(RetAttrs, 1) ||
- ParseType(RetType, RetTypeLoc))
+ ParseType(RetType, RetTypeLoc, true /*void allowed*/))
return true;
// Verify that the linkage is ok.
@@ -2146,6 +2160,10 @@
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);
@@ -2307,6 +2325,7 @@
if (Token == lltok::Eof)
return TokError("found end of file when expecting more instructions");
LocTy Loc = Lex.getLoc();
+ unsigned KeywordVal = Lex.getUIntVal();
Lex.Lex(); // Eat the keyword.
switch (Token) {
@@ -2321,24 +2340,24 @@
// Binary Operators.
case lltok::kw_add:
case lltok::kw_sub:
- case lltok::kw_mul: return ParseArithmetic(Inst, PFS, Lex.getUIntVal(), 0);
+ case lltok::kw_mul: return ParseArithmetic(Inst, PFS, KeywordVal, 0);
case lltok::kw_udiv:
case lltok::kw_sdiv:
case lltok::kw_urem:
- case lltok::kw_srem: return ParseArithmetic(Inst, PFS, Lex.getUIntVal(), 1);
+ case lltok::kw_srem: return ParseArithmetic(Inst, PFS, KeywordVal, 1);
case lltok::kw_fdiv:
- case lltok::kw_frem: return ParseArithmetic(Inst, PFS, Lex.getUIntVal(), 2);
+ case lltok::kw_frem: return ParseArithmetic(Inst, PFS, KeywordVal, 2);
case lltok::kw_shl:
case lltok::kw_lshr:
case lltok::kw_ashr:
case lltok::kw_and:
case lltok::kw_or:
- case lltok::kw_xor: return ParseLogical(Inst, PFS, Lex.getUIntVal());
+ case lltok::kw_xor: return ParseLogical(Inst, PFS, KeywordVal);
case lltok::kw_icmp:
case lltok::kw_fcmp:
case lltok::kw_vicmp:
- case lltok::kw_vfcmp: return ParseCompare(Inst, PFS, Lex.getUIntVal());
+ case lltok::kw_vfcmp: return ParseCompare(Inst, PFS, KeywordVal);
// Casts.
case lltok::kw_trunc:
case lltok::kw_zext:
@@ -2351,7 +2370,7 @@
case lltok::kw_fptoui:
case lltok::kw_fptosi:
case lltok::kw_inttoptr:
- case lltok::kw_ptrtoint: return ParseCast(Inst, PFS, Lex.getUIntVal());
+ case lltok::kw_ptrtoint: return ParseCast(Inst, PFS, KeywordVal);
// Other.
case lltok::kw_select: return ParseSelect(Inst, PFS);
case lltok::kw_va_arg: return ParseVA_Arg(Inst, PFS);
@@ -2363,7 +2382,7 @@
case lltok::kw_tail: return ParseCall(Inst, PFS, true);
// Memory.
case lltok::kw_alloca:
- case lltok::kw_malloc: return ParseAlloc(Inst, PFS, Lex.getUIntVal());
+ case lltok::kw_malloc: return ParseAlloc(Inst, PFS, KeywordVal);
case lltok::kw_free: return ParseFree(Inst, PFS);
case lltok::kw_load: return ParseLoad(Inst, PFS, false);
case lltok::kw_store: return ParseStore(Inst, PFS, false);
@@ -2434,7 +2453,7 @@
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();
@@ -2564,7 +2583,7 @@
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) ||
@@ -2764,10 +2783,12 @@
ParseType(DestTy))
return true;
- if (!CastInst::castIsValid((Instruction::CastOps)Opc, Op, DestTy))
+ if (!CastInst::castIsValid((Instruction::CastOps)Opc, Op, DestTy)) {
+ CastInst::castIsValid((Instruction::CastOps)Opc, Op, DestTy);
return Error(Loc, "invalid cast opcode for cast from '" +
Op->getType()->getDescription() + "' to '" +
DestTy->getDescription() + "'");
+ }
Inst = CastInst::Create((Instruction::CastOps)Opc, Op, DestTy);
return false;
}
@@ -2920,7 +2941,7 @@
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))
Modified: llvm/branches/Apple/Dib/lib/AsmParser/LLParser.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/lib/AsmParser/LLParser.h?rev=66482&r1=66481&r2=66482&view=diff
==============================================================================
--- llvm/branches/Apple/Dib/lib/AsmParser/LLParser.h (original)
+++ llvm/branches/Apple/Dib/lib/AsmParser/LLParser.h Mon Mar 9 17:20:16 2009
@@ -139,10 +139,10 @@
bool ParseAlias(const std::string &Name, LocTy Loc, unsigned Visibility);
// Type Parsing.
- bool ParseType(PATypeHolder &Result);
- bool ParseType(PATypeHolder &Result, LocTy &Loc) {
+ bool ParseType(PATypeHolder &Result, bool AllowVoid = false);
+ bool ParseType(PATypeHolder &Result, LocTy &Loc, bool AllowVoid = false) {
Loc = Lex.getLoc();
- return ParseType(Result);
+ return ParseType(Result, AllowVoid);
}
bool ParseTypeRec(PATypeHolder &H);
bool ParseStructType(PATypeHolder &H, bool Packed);
Added: llvm/branches/Apple/Dib/test/Assembler/2009-02-28-CastOpc.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/test/Assembler/2009-02-28-CastOpc.ll?rev=66482&view=auto
==============================================================================
--- llvm/branches/Apple/Dib/test/Assembler/2009-02-28-CastOpc.ll (added)
+++ llvm/branches/Apple/Dib/test/Assembler/2009-02-28-CastOpc.ll Mon Mar 9 17:20:16 2009
@@ -0,0 +1,8 @@
+; RUN: llvm-as < %s | llvm-dis
+
+type i32
+
+define void @foo() {
+ bitcast %0* null to i32*
+ ret void
+}
More information about the llvm-commits
mailing list