[svn r231] Changed: warnings are no longer treated as an error.

Added some comments and cleaned up CallExp::toElem a tiny bit.
Fixed: struct literals always reported inplace assignment even if they allocated a temporary.
Fixed: passing stuff to a D-style vararg which did inplace assignment was generated suboptimal code.
This commit is contained in:
Tomas Lindquist Olsen 2008-06-03 13:51:09 +02:00
parent d50cb50aaf
commit 590d44d302
8 changed files with 153 additions and 113 deletions

View file

@ -43,9 +43,8 @@ Expression *Expression::implicitCastTo(Scope *sc, Type *t)
if (e->op == TOKint64)
return e->implicitCastTo(sc, t);
fprintf(stdmsg, "warning - ");
error("implicit conversion of expression (%s) of type %s to %s can cause loss of data",
toChars(), type->toChars(), t->toChars());
warning("%s: implicit conversion of expression (%s) of type %s to %s can cause loss of data",
loc.toChars(), toChars(), type->toChars(), t->toChars());
}
return castTo(sc, t);
}

View file

@ -308,7 +308,7 @@ void FuncDeclaration::semantic(Scope *sc)
#if V2
if (!isOverride() && global.params.warnings)
error("overrides base class function %s, but is not marked with 'override'", fdv->toPrettyChars());
warning("%s: overrides base class function %s, but is not marked with 'override'", locToChars() fdv->toPrettyChars());
#endif
if (fdv->toParent() == parent)
@ -1056,8 +1056,7 @@ void FuncDeclaration::semantic3(Scope *sc)
{ Expression *e;
if (global.params.warnings)
{ fprintf(stdmsg, "warning - ");
error("no return at end of function");
{ warning("%s: no return at end of function", locToChars());
}
if (global.params.useAssert &&

View file

@ -255,6 +255,7 @@ Dsymbol *Scope::search(Loc loc, Identifier *ident, Dsymbol **pscopesym)
sc->enclosing &&
sc->enclosing->search(loc, ident, NULL))
{
// WTF ?
if (global.params.warnings)
fprintf(stdmsg, "warning - ");
error(s->loc, "array 'length' hides other 'length' name in outer scope");

View file

@ -531,8 +531,7 @@ int CompoundStatement::fallOffEnd()
if (!falloff && global.params.warnings && !s->comeFrom())
{
fprintf(stdmsg, "warning - ");
s->error("statement is not reachable");
warning("%s: statement is not reachable", s->loc.toChars());
}
falloff = s->fallOffEnd();
}
@ -2049,8 +2048,7 @@ Statement *SwitchStatement::semantic(Scope *sc)
{ hasNoDefault = 1;
if (global.params.warnings)
{ fprintf(stdmsg, "warning - ");
error("switch statement has no default");
{ warning("%s: switch statement has no default", loc.toChars());
}
// Generate runtime error if the default is hit

View file

@ -799,7 +799,9 @@ void DtoVariadicArgument(Expression* argexp, LLValue* dst)
Logger::println("DtoVariadicArgument");
LOG_SCOPE;
DVarValue* vv = new DVarValue(argexp->type, dst, true);
gIR->exps.push_back(IRExp(NULL, argexp, vv));
DtoAssign(vv, argexp->toElem(gIR));
gIR->exps.pop_back();
}
//////////////////////////////////////////////////////////////////////////////////////////

View file

@ -867,6 +867,8 @@ DValue* ModAssignExp::toElem(IRState* p)
//////////////////////////////////////////////////////////////////////////////////////////
// TODO: the method below could really use a cleanup/splitup
DValue* CallExp::toElem(IRState* p)
{
Logger::print("CallExp::toElem: %s | %s\n", toChars(), type->toChars());
@ -911,19 +913,22 @@ DValue* CallExp::toElem(IRState* p)
assert(tf);
}
// magic stuff
// handling of special intrinsics
bool va_magic = false;
bool va_intrinsic = false;
DFuncValue* dfv = fn->isFunc();
if (dfv && dfv->func) {
FuncDeclaration* fndecl = dfv->func;
// vararg intrinsic
if (fndecl->llvmInternal == LLVMva_intrinsic) {
va_magic = true;
va_intrinsic = true;
}
// va_start instruction
else if (fndecl->llvmInternal == LLVMva_start) {
va_magic = true;
}
// va_arg instruction
else if (fndecl->llvmInternal == LLVMva_arg) {
//Argument* fnarg = Argument::getNth(tf->parameters, 0);
Expression* exp = (Expression*)arguments->data[0];
@ -933,11 +938,14 @@ DValue* CallExp::toElem(IRState* p)
if (DtoIsPassedByRef(t))
llt = getPtrToType(llt);
// TODO
// issue a warning for broken va_arg instruction.
if (strcmp(global.params.llvmArch, "x86") != 0) {
warning("%s: va_arg for C variadic functions is broken for anything but x86", loc.toChars());
warning("%s: va_arg for C variadic functions is probably broken for anything but x86", loc.toChars());
}
// done
return new DImValue(type, p->ir->CreateVAArg(expelem->getLVal(),llt,"tmp"));
}
// alloca
else if (fndecl->llvmInternal == LLVMalloca) {
//Argument* fnarg = Argument::getNth(tf->parameters, 0);
Expression* exp = (Expression*)arguments->data[0];
@ -945,6 +953,7 @@ DValue* CallExp::toElem(IRState* p)
if (expv->getType()->toBasetype()->ty != Tint32)
expv = DtoCast(expv, Type::tint32);
LLValue* alloc = new llvm::AllocaInst(llvm::Type::Int8Ty, expv->getRVal(), "alloca", p->scopebb());
// done
return new DImValue(type, alloc);
}
}
@ -965,6 +974,8 @@ DValue* CallExp::toElem(IRState* p)
const llvm::FunctionType* llfnty = 0;
// TODO: review the stuff below, using the llvm type to choose seem like a bad idea. the D type should be used.
//
// normal function call
if (llvm::isa<llvm::FunctionType>(funcval->getType())) {
llfnty = llvm::cast<llvm::FunctionType>(funcval->getType());
@ -1082,11 +1093,8 @@ DValue* CallExp::toElem(IRState* p)
llargs[j] = DtoBitCast(expelem->getLVal(), getPtrToType(llvm::Type::Int8Ty));
}
}
// regular arguments
else
{
// d variadic function?
if (tf->linkage == LINKd && tf->varargs == 1)
// d variadic function
else if (tf->linkage == LINKd && tf->varargs == 1)
{
Logger::println("doing d-style variadic arguments");
@ -1165,8 +1173,9 @@ DValue* CallExp::toElem(IRState* p)
// make sure arg vector has the right size
llargs.resize(nimplicit+begin+2);
}
// normal function
else {
// normal function call
else
{
Logger::println("doing normal arguments");
for (int i=0; i<arguments->dim; i++,j++) {
Argument* fnarg = Argument::getNth(tf->parameters, i);
@ -1190,7 +1199,6 @@ DValue* CallExp::toElem(IRState* p)
}
}
}
}
#if 0
Logger::println("%d params passed", n);
@ -2720,11 +2728,13 @@ DValue* StructLiteralExp::toElem(IRState* p)
const LLType* llt = DtoType(type);
LLValue* mem = 0;
bool isinplace = true;
// temporary struct literal
if (!p->topexp() || p->topexp()->e2 != this)
{
sptr = new llvm::AllocaInst(llt,"tmpstructliteral",p->topallocapoint());
isinplace = false;
}
// already has memory
else
@ -2777,7 +2787,7 @@ DValue* StructLiteralExp::toElem(IRState* p)
j++;
}
return new DImValue(type, sptr, true);
return new DImValue(type, sptr, isinplace);
}
//////////////////////////////////////////////////////////////////////////////////////////

View file

@ -748,6 +748,7 @@ tangotests
tangotests/a.d
tangotests/aa1.d
tangotests/aa2.d
tangotests/align1.d
tangotests/b.d
tangotests/c.d
tangotests/classes1.d
@ -757,6 +758,7 @@ tangotests/f.d
tangotests/files1.d
tangotests/h.d
tangotests/i.d
tangotests/ina1.d
tangotests/j.d
tangotests/k.d
tangotests/l.d
@ -777,6 +779,7 @@ tangotests/templ1.d
tangotests/vararg1.d
tangotests/vararg2.d
tangotests/vararg3.d
tangotests/vararg4.d
test
test/a.d
test/aa1.d

View file

@ -35,6 +35,16 @@ class Obj
}
}
struct TLA
{
char[3] acronym;
char[] toString()
{
return acronym;
}
}
void main()
{
User user = User("Bob Doe", "bd", 47);
@ -81,6 +91,24 @@ void main()
print("Mixed:\n");
print(123, ' ', 42.536f, " foobar ", ia1, ' ', user, '\n');
print(42, ' ', cast(byte)12, ' ', user, ' ', cast(short)1445, " foo\n");
print("International:\n");
print('æ','ø','å','\n');
print('Æ','Ø','Å','\n');
print("rød grød med fløde\n");
print("Heiße\n");
print("TLAs:\n");
TLA tla1 = TLA("FBI");
TLA tla2 = TLA("CIA");
TLA tla3 = TLA("TLA");
print(tla1);
print(tla2);
print(tla3, '\n');
print(tla1, tla2, tla3, '\n');
print(TLA("FBI"), TLA("CIA"), TLA("TLA"), '\n');
print("Done!\n");
}
private void* get_va_arg(TypeInfo ti, ref void* vp)