llvm.org GIT mirror llvm / 3cb4dda
Fix a compilation error (jump to case label). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36539 91177308-0d34-0410-b5e6-96231b3b80d8 Reid Spencer 13 years ago
1 changed file(s) with 64 addition(s) and 77 deletion(s). Raw diff Collapse all Expand all
138138 // GetForwardRefForGlobal - Check to see if there is a forward reference
139139 // for this global. If so, remove it from the GlobalRefs map and return it.
140140 // If not, just return null.
141 GlobalValue *GetForwardRefForGlobal(const PointerType *PTy, ValID ID) {
141 GlobalValue *GetForwardRefForGlobal(const PointerType *PTy, ParamAttrsList *PAL,
142 ValID ID) {
142143 // Check to see if there is a forward reference to this global variable...
143144 // if there is, eliminate it and patch the reference to use the new def'n.
144145 GlobalRefsType::iterator I = GlobalRefs.find(std::make_pair(PTy, ID));
145146 GlobalValue *Ret = 0;
146147 if (I != GlobalRefs.end()) {
147148 Ret = I->second;
148 GlobalRefs.erase(I);
149 if (PAL && isa(Ret))
150 Ret = cast(Ret)->getParamAttrs() == PAL ? Ret : 0;
151 if (Ret)
152 GlobalRefs.erase(I);
149153 }
150154 return Ret;
151155 }
481485 //
482486 switch (ID.Type) {
483487 case ValID::GlobalName:
484 case ValID::GlobalID:
488 case ValID::GlobalID: {
485489 const PointerType *PTy = dyn_cast(Ty);
486490 if (!PTy) {
487491 GenerateError("Invalid type for reference to global" );
493497 else
494498 V = new GlobalVariable(ElTy, false, GlobalValue::ExternalLinkage);
495499 break;
500 }
496501 default:
497502 V = new Argument(Ty);
498503 }
742747 ID = ValID::createGlobalID(CurModule.Values.size());
743748 }
744749
745 if (GlobalValue *FWGV = CurModule.GetForwardRefForGlobal(PTy, ID)) {
750 if (GlobalValue *FWGV = CurModule.GetForwardRefForGlobal(PTy, 0, ID)) {
746751 // Move the global to the end of the list, from whereever it was
747752 // previously inserted.
748753 GlobalVariable *GV = cast(FWGV);
13221327 UR_OUT("New Upreference!\n");
13231328 CHECK_FOR_ERROR
13241329 }
1325 | Types '(' ArgTypeListI ')' OptFuncAttrs {
1330 | Types '(' ArgTypeListI ')' {
13261331 std::vector Params;
1327 ParamAttrsVector Attrs;
1328 if ($5 != ParamAttr::None) {
1329 ParamAttrsWithIndex X; X.index = 0; X.attrs = $5;
1330 Attrs.push_back(X);
1331 }
13321332 unsigned index = 1;
13331333 TypeWithAttrsList::iterator I = $3->begin(), E = $3->end();
13341334 for (; I != E; ++I, ++index) {
13351335 const Type *Ty = I->Ty->get();
13361336 Params.push_back(Ty);
1337 if (Ty != Type::VoidTy)
1338 if (I->Attrs != ParamAttr::None) {
1339 ParamAttrsWithIndex X; X.index = index; X.attrs = I->Attrs;
1340 Attrs.push_back(X);
1341 }
13421337 }
13431338 bool isVarArg = Params.size() && Params.back() == Type::VoidTy;
13441339 if (isVarArg) Params.pop_back();
13451340
1346 ParamAttrsList *ActualAttrs = 0;
1347 if (!Attrs.empty())
1348 ActualAttrs = ParamAttrsList::get(Attrs);
1349 FunctionType *FT = FunctionType::get(*$1, Params, isVarArg, ActualAttrs);
1341 FunctionType *FT = FunctionType::get(*$1, Params, isVarArg);
13501342 delete $3; // Delete the argument list
13511343 delete $1; // Delete the return type handle
13521344 $$ = new PATypeHolder(HandleUpRefs(FT));
13531345 CHECK_FOR_ERROR
13541346 }
1355 | VOID '(' ArgTypeListI ')' OptFuncAttrs {
1347 | VOID '(' ArgTypeListI ')' {
13561348 std::vector Params;
1357 ParamAttrsVector Attrs;
1358 if ($5 != ParamAttr::None) {
1359 ParamAttrsWithIndex X; X.index = 0; X.attrs = $5;
1360 Attrs.push_back(X);
1361 }
13621349 TypeWithAttrsList::iterator I = $3->begin(), E = $3->end();
13631350 unsigned index = 1;
13641351 for ( ; I != E; ++I, ++index) {
13651352 const Type* Ty = I->Ty->get();
13661353 Params.push_back(Ty);
1367 if (Ty != Type::VoidTy)
1368 if (I->Attrs != ParamAttr::None) {
1369 ParamAttrsWithIndex X; X.index = index; X.attrs = I->Attrs;
1370 Attrs.push_back(X);
1371 }
13721354 }
13731355 bool isVarArg = Params.size() && Params.back() == Type::VoidTy;
13741356 if (isVarArg) Params.pop_back();
13751357
1376 ParamAttrsList *ActualAttrs = 0;
1377 if (!Attrs.empty())
1378 ActualAttrs = ParamAttrsList::get(Attrs);
1379
1380 FunctionType *FT = FunctionType::get($1, Params, isVarArg, ActualAttrs);
1358 FunctionType *FT = FunctionType::get($1, Params, isVarArg);
13811359 delete $3; // Delete the argument list
13821360 $$ = new PATypeHolder(HandleUpRefs(FT));
13831361 CHECK_FOR_ERROR
14311409 ;
14321410
14331411 ArgType
1434 : Types OptParamAttrs {
1412 : Types {
14351413 $$.Ty = $1;
1436 $$.Attrs = $2;
1414 $$.Attrs = ParamAttr::None;
14371415 }
14381416 ;
14391417
22382216 if (!Attrs.empty())
22392217 PAL = ParamAttrsList::get(Attrs);
22402218
2241 FunctionType *FT = FunctionType::get(*$2, ParamTypeList, isVarArg, PAL);
2219 FunctionType *FT = FunctionType::get(*$2, ParamTypeList, isVarArg);
22422220 const PointerType *PFT = PointerType::get(FT);
22432221 delete $2;
22442222
22512229
22522230 Function *Fn = 0;
22532231 // See if this function was forward referenced. If so, recycle the object.
2254 if (GlobalValue *FWRef = CurModule.GetForwardRefForGlobal(PFT, ID)) {
2232 if (GlobalValue *FWRef = CurModule.GetForwardRefForGlobal(PFT, PAL, ID)) {
22552233 // Move the function to the end of the list, from whereever it was
22562234 // previously inserted.
22572235 Fn = cast(FWRef);
22592237 CurModule.CurrentModule->getFunctionList().push_back(Fn);
22602238 } else if (!FunctionName.empty() && // Merge with an earlier prototype?
22612239 (Fn = CurModule.CurrentModule->getFunction(FunctionName))) {
2262 if (Fn->getFunctionType() != FT) {
2240 if (Fn->getFunctionType() != FT || PAL != Fn->getParamAttrs()) {
22632241 // The existing function doesn't have the same type. This is an overload
22642242 // error.
22652243 GEN_ERROR("Overload of function '" + FunctionName + "' not permitted.");
22762254 } else { // Not already defined?
22772255 Fn = new Function(FT, GlobalValue::ExternalWeakLinkage, FunctionName,
22782256 CurModule.CurrentModule);
2257 Fn->setParamAttrs(PAL);
22792258
22802259 InsertValue(Fn, CurModule.Values);
22812260 }
25692548 !(Ty = dyn_cast(PFTy->getElementType()))) {
25702549 // Pull out the types of all of the arguments...
25712550 std::vector ParamTypes;
2572 ParamAttrsVector Attrs;
2573 if ($8 != ParamAttr::None) {
2574 ParamAttrsWithIndex PAWI; PAWI.index = 0; PAWI.attrs = 8;
2575 Attrs.push_back(PAWI);
2576 }
25772551 ValueRefList::iterator I = $6->begin(), E = $6->end();
2578 unsigned index = 1;
2579 for (; I != E; ++I, ++index) {
2552 for (; I != E; ++I) {
25802553 const Type *Ty = I->Val->getType();
25812554 if (Ty == Type::VoidTy)
25822555 GEN_ERROR("Short call syntax cannot be used with varargs");
25832556 ParamTypes.push_back(Ty);
2584 if (I->Attrs != ParamAttr::None) {
2585 ParamAttrsWithIndex PAWI; PAWI.index = index; PAWI.attrs = I->Attrs;
2586 Attrs.push_back(PAWI);
2587 }
25882557 }
2589
2590 ParamAttrsList *PAL = 0;
2591 if (!Attrs.empty())
2592 PAL = ParamAttrsList::get(Attrs);
2593 Ty = FunctionType::get($3->get(), ParamTypes, false, PAL);
2558 Ty = FunctionType::get($3->get(), ParamTypes, false);
25942559 PFTy = PointerType::get(Ty);
25952560 }
25962561
26022567 CHECK_FOR_ERROR
26032568 BasicBlock *Except = getBBVal($14);
26042569 CHECK_FOR_ERROR
2570
2571 ParamAttrsVector Attrs;
2572 if ($8 != ParamAttr::None) {
2573 ParamAttrsWithIndex PAWI; PAWI.index = 0; PAWI.attrs = 8;
2574 Attrs.push_back(PAWI);
2575 }
26052576
26062577 // Check the arguments
26072578 ValueList Args;
26162587 FunctionType::param_iterator I = Ty->param_begin();
26172588 FunctionType::param_iterator E = Ty->param_end();
26182589 ValueRefList::iterator ArgI = $6->begin(), ArgE = $6->end();
2619
2590 unsigned index = 1;
26202591 for (; ArgI != ArgE && I != E; ++ArgI, ++I) {
26212592 if (ArgI->Val->getType() != *I)
26222593 GEN_ERROR("Parameter " + ArgI->Val->getName()+ " is not of type '" +
26232594 (*I)->getDescription() + "'");
26242595 Args.push_back(ArgI->Val);
2596 if (ArgI->Attrs != ParamAttr::None) {
2597 ParamAttrsWithIndex PAWI; PAWI.index = index; PAWI.attrs = ArgI->Attrs;
2598 Attrs.push_back(PAWI);
2599 }
26252600 }
26262601
26272602 if (Ty->isVarArg()) {
26322607 GEN_ERROR("Invalid number of parameters detected");
26332608 }
26342609
2610 ParamAttrsList *PAL = 0;
2611 if (!Attrs.empty())
2612 PAL = ParamAttrsList::get(Attrs);
2613 if (isa(V))
2614 if (PAL != cast(V)->getParamAttrs())
2615 GEN_ERROR("Invalid parameter attributes for function invoked");
2616
26352617 // Create the InvokeInst
26362618 InvokeInst *II = new InvokeInst(V, Normal, Except, &Args[0], Args.size());
26372619 II->setCallingConv($2);
2620 II->setParamAttrs(PAL);
26382621 $$ = II;
26392622 delete $6;
26402623 CHECK_FOR_ERROR
28792862 !(Ty = dyn_cast(PFTy->getElementType()))) {
28802863 // Pull out the types of all of the arguments...
28812864 std::vector ParamTypes;
2882 ParamAttrsVector Attrs;
2883 if ($8 != ParamAttr::None) {
2884 ParamAttrsWithIndex PAWI; PAWI.index = 0; PAWI.attrs = $8;
2885 Attrs.push_back(PAWI);
2886 }
2887 unsigned index = 1;
28882865 ValueRefList::iterator I = $6->begin(), E = $6->end();
2889 for (; I != E; ++I, ++index) {
2866 for (; I != E; ++I) {
28902867 const Type *Ty = I->Val->getType();
28912868 if (Ty == Type::VoidTy)
28922869 GEN_ERROR("Short call syntax cannot be used with varargs");
28932870 ParamTypes.push_back(Ty);
2894 if (I->Attrs != ParamAttr::None) {
2895 ParamAttrsWithIndex PAWI; PAWI.index = index; PAWI.attrs = I->Attrs;
2896 Attrs.push_back(PAWI);
2897 }
28982871 }
2899
2900 ParamAttrsList *PAL = 0;
2901 if (!Attrs.empty())
2902 PAL = ParamAttrsList::get(Attrs);
2903
2904 Ty = FunctionType::get($3->get(), ParamTypes, false, PAL);
2872 Ty = FunctionType::get($3->get(), ParamTypes, false);
29052873 PFTy = PointerType::get(Ty);
29062874 }
29072875
29172885 theF->getName() + "'");
29182886 }
29192887
2888 // Set up the ParamAttrs for the function
2889 ParamAttrsVector Attrs;
2890 if ($8 != ParamAttr::None) {
2891 ParamAttrsWithIndex PAWI; PAWI.index = 0; PAWI.attrs = $8;
2892 Attrs.push_back(PAWI);
2893 }
29202894 // Check the arguments
29212895 ValueList Args;
29222896 if ($6->empty()) { // Has no arguments?
29262900 "expects arguments");
29272901 } else { // Has arguments?
29282902 // Loop through FunctionType's arguments and ensure they are specified
2929 // correctly!
2930 //
2903 // correctly. Also, gather any parameter attributes.
29312904 FunctionType::param_iterator I = Ty->param_begin();
29322905 FunctionType::param_iterator E = Ty->param_end();
29332906 ValueRefList::iterator ArgI = $6->begin(), ArgE = $6->end();
2934
2907 unsigned index = 1;
29352908 for (; ArgI != ArgE && I != E; ++ArgI, ++I) {
29362909 if (ArgI->Val->getType() != *I)
29372910 GEN_ERROR("Parameter " + ArgI->Val->getName()+ " is not of type '" +
29382911 (*I)->getDescription() + "'");
29392912 Args.push_back(ArgI->Val);
2913 if (ArgI->Attrs != ParamAttr::None) {
2914 ParamAttrsWithIndex PAWI; PAWI.index = index; PAWI.attrs = ArgI->Attrs;
2915 Attrs.push_back(PAWI);
2916 }
29402917 }
29412918 if (Ty->isVarArg()) {
29422919 if (I == E)
29452922 } else if (I != E || ArgI != ArgE)
29462923 GEN_ERROR("Invalid number of parameters detected");
29472924 }
2925
2926 // Finish off the ParamAttrs and check them
2927 ParamAttrsList *PAL = 0;
2928 if (!Attrs.empty())
2929 PAL = ParamAttrsList::get(Attrs);
2930 if (isa(V))
2931 if (PAL != cast(V)->getParamAttrs())
2932 GEN_ERROR("Invalid parameter attributes for function called");
2933
29482934 // Create the call node
29492935 CallInst *CI = new CallInst(V, &Args[0], Args.size());
29502936 CI->setTailCall($1);
29512937 CI->setCallingConv($2);
2938 CI->setParamAttrs(PAL);
29522939 $$ = CI;
29532940 delete $6;
29542941 delete $3;