comparison gen/llvmhelpers.cpp @ 796:6e7a4c3b64d2

Error instead of assert when trying to build a default initializer for void[n].
author Christian Kamm <kamm incasoftware de>
date Sat, 29 Nov 2008 12:28:10 +0100
parents 661384d6a936
children 340acf1535d0
comparison
equal deleted inserted replaced
795:06ba66bc0689 796:6e7a4c3b64d2
969 969
970 bool emitRTstaticInit = false; 970 bool emitRTstaticInit = false;
971 971
972 LLConstant* _init = 0; 972 LLConstant* _init = 0;
973 if (vd->parent && vd->parent->isFuncDeclaration() && vd->init && vd->init->isExpInitializer()) { 973 if (vd->parent && vd->parent->isFuncDeclaration() && vd->init && vd->init->isExpInitializer()) {
974 _init = DtoConstInitializer(vd->type, NULL); 974 _init = DtoConstInitializer(vd->loc, vd->type, NULL);
975 emitRTstaticInit = true; 975 emitRTstaticInit = true;
976 } 976 }
977 else { 977 else {
978 _init = DtoConstInitializer(vd->type, vd->init); 978 _init = DtoConstInitializer(vd->loc, vd->type, vd->init);
979 } 979 }
980 980
981 const LLType* _type = DtoType(vd->type); 981 const LLType* _type = DtoType(vd->type);
982 Type* t = vd->type->toBasetype(); 982 Type* t = vd->type->toBasetype();
983 983
1394 /****************************************************************************************/ 1394 /****************************************************************************************/
1395 /*//////////////////////////////////////////////////////////////////////////////////////// 1395 /*////////////////////////////////////////////////////////////////////////////////////////
1396 // INITIALIZER HELPERS 1396 // INITIALIZER HELPERS
1397 ////////////////////////////////////////////////////////////////////////////////////////*/ 1397 ////////////////////////////////////////////////////////////////////////////////////////*/
1398 1398
1399 LLConstant* DtoConstInitializer(Type* type, Initializer* init) 1399 LLConstant* DtoConstInitializer(Loc& loc, Type* type, Initializer* init)
1400 { 1400 {
1401 LLConstant* _init = 0; // may return zero 1401 LLConstant* _init = 0; // may return zero
1402 if (!init) 1402 if (!init)
1403 { 1403 {
1404 Logger::println("const default initializer for %s", type->toChars()); 1404 Logger::println("const default initializer for %s", type->toChars());
1405 _init = DtoDefaultInit(type); 1405 _init = DtoDefaultInit(loc, type);
1406 } 1406 }
1407 else if (ExpInitializer* ex = init->isExpInitializer()) 1407 else if (ExpInitializer* ex = init->isExpInitializer())
1408 { 1408 {
1409 Logger::println("const expression initializer"); 1409 Logger::println("const expression initializer");
1410 _init = ex->exp->toConstElem(gIR); 1410 _init = ex->exp->toConstElem(gIR);
1431 return _init; 1431 return _init;
1432 } 1432 }
1433 1433
1434 ////////////////////////////////////////////////////////////////////////////////////////// 1434 //////////////////////////////////////////////////////////////////////////////////////////
1435 1435
1436 LLConstant* DtoConstFieldInitializer(Type* t, Initializer* init) 1436 LLConstant* DtoConstFieldInitializer(Loc& loc, Type* t, Initializer* init)
1437 { 1437 {
1438 Logger::println("DtoConstFieldInitializer"); 1438 Logger::println("DtoConstFieldInitializer");
1439 LOG_SCOPE; 1439 LOG_SCOPE;
1440 1440
1441 const LLType* _type = DtoType(t); 1441 const LLType* _type = DtoType(t);
1442 1442
1443 LLConstant* _init = DtoConstInitializer(t, init); 1443 LLConstant* _init = DtoConstInitializer(loc, t, init);
1444 assert(_init); 1444 assert(_init);
1445 if (_type != _init->getType()) 1445 if (_type != _init->getType())
1446 { 1446 {
1447 if (Logger::enabled()) 1447 if (Logger::enabled())
1448 Logger::cout() << "field init is: " << *_init << " type should be " << *_type << '\n'; 1448 Logger::cout() << "field init is: " << *_init << " type should be " << *_type << '\n';
1566 } 1566 }
1567 1567
1568 return val; 1568 return val;
1569 } 1569 }
1570 1570
1571 LLConstant* DtoDefaultInit(Type* type) 1571 LLConstant* DtoDefaultInit(Loc& loc, Type* type)
1572 { 1572 {
1573 Expression* exp = type->defaultInit(); 1573 Expression* exp = type->defaultInit();
1574 1574
1575 Type* expbase = exp->type->toBasetype(); 1575 Type* expbase = exp->type->toBasetype();
1576 Type* base = type->toBasetype(); 1576 Type* base = type->toBasetype();
1578 // if not the same basetypes, we won't get the same llvm types either 1578 // if not the same basetypes, we won't get the same llvm types either
1579 if (!expbase->equals(base)) 1579 if (!expbase->equals(base))
1580 { 1580 {
1581 if (base->ty == Tsarray) 1581 if (base->ty == Tsarray)
1582 { 1582 {
1583 if (base->nextOf()->toBasetype()->ty == Tvoid) {
1584 error(loc, "static arrays of voids have no default initializer");
1585 fatal();
1586 }
1587
1583 Logger::println("type is a static array, building constant array initializer to single value"); 1588 Logger::println("type is a static array, building constant array initializer to single value");
1584 return expand_to_sarray(base, exp); 1589 return expand_to_sarray(base, exp);
1585 } 1590 }
1586 else 1591 else
1587 { 1592 {