llvm.org GIT mirror llvm / 0286835
Kill using declarations Kill code for invalid operations on pointers git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@5856 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 17 years ago
1 changed file(s) with 111 addition(s) and 106 deletion(s). Raw diff Collapse all Expand all
1919 #include // For fmod
2020 #include
2121 #include
22 using std::vector;
23 using std::cout;
24 using std::cerr;
2522
2623 Interpreter *TheEE = 0;
2724
5350 ProfileStructureFields("profilestructfields",
5451 cl::desc("Profile Structure Field Accesses"));
5552 #include
56 static std::mapvector > FieldAccessCounts;
53 static std::mapstd::vector > FieldAccessCounts;
5754 #endif
5855
5956 sigjmp_buf SignalRecoverBuffer;
108105 getOperandValue(CE->getOperand(1), SF),
109106 CE->getType());
110107 default:
111 cerr << "Unhandled ConstantExpr: " << CE << "\n";
108 std::cerr << "Unhandled ConstantExpr: " << CE << "\n";
112109 abort();
113110 return GenericValue();
114111 }
127124
128125 static void printOperandInfo(Value *V, ExecutionContext &SF) {
129126 if (isa(V)) {
130 cout << "Constant Pool Value\n";
127 std::cout << "Constant Pool Value\n";
131128 } else if (isa(V)) {
132 cout << "Global Value\n";
129 std::cout << "Global Value\n";
133130 } else {
134131 unsigned TyP = V->getType()->getUniqueID(); // TypePlane for value
135132 unsigned Slot = getOperandSlot(V);
136 cout << "Value=" << (void*)V << " TypeID=" << TyP << " Slot=" << Slot
137 << " Addr=" << &SF.Values[TyP][Slot] << " SF=" << &SF
138 << " Contents=0x";
133 std::cout << "Value=" << (void*)V << " TypeID=" << TyP << " Slot=" << Slot
134 << " Addr=" << &SF.Values[TyP][Slot] << " SF=" << &SF
135 << " Contents=0x";
139136
140137 const unsigned char *Buf = (const unsigned char*)&SF.Values[TyP][Slot];
141138 for (unsigned i = 0; i < sizeof(GenericValue); ++i) {
142139 unsigned char Cur = Buf[i];
143 cout << ( Cur >= 160? char((Cur>>4)+'A'-10) : char((Cur>>4) + '0'))
144 << ((Cur&15) >= 10? char((Cur&15)+'A'-10) : char((Cur&15) + '0'));
140 std::cout << ( Cur >= 160?char((Cur>>4)+'A'-10):char((Cur>>4) + '0'))
141 << ((Cur&15) >= 10?char((Cur&15)+'A'-10):char((Cur&15) + '0'));
145142 }
146 cout << "\n";
143 std::cout << "\n";
147144 }
148145 }
149146
152149 static void SetValue(Value *V, GenericValue Val, ExecutionContext &SF) {
153150 unsigned TyP = V->getType()->getUniqueID(); // TypePlane for value
154151
155 //cout << "Setting value: " << &SF.Values[TyP][getOperandSlot(V)] << "\n";
152 //std::cout << "Setting value: " << &SF.Values[TyP][getOperandSlot(V)]<< "\n";
156153 SF.Values[TyP][getOperandSlot(V)] = Val;
157154 }
158155
189186 IMPLEMENT_BINARY_OPERATOR(+, Long);
190187 IMPLEMENT_BINARY_OPERATOR(+, Float);
191188 IMPLEMENT_BINARY_OPERATOR(+, Double);
192 IMPLEMENT_BINARY_OPERATOR(+, Pointer);
193 default:
194 cout << "Unhandled type for Add instruction: " << Ty << "\n";
189 default:
190 std::cout << "Unhandled type for Add instruction: " << *Ty << "\n";
191 abort();
195192 }
196193 return Dest;
197194 }
210207 IMPLEMENT_BINARY_OPERATOR(-, Long);
211208 IMPLEMENT_BINARY_OPERATOR(-, Float);
212209 IMPLEMENT_BINARY_OPERATOR(-, Double);
213 IMPLEMENT_BINARY_OPERATOR(-, Pointer);
214 default:
215 cout << "Unhandled type for Sub instruction: " << Ty << "\n";
210 default:
211 std::cout << "Unhandled type for Sub instruction: " << *Ty << "\n";
212 abort();
216213 }
217214 return Dest;
218215 }
231228 IMPLEMENT_BINARY_OPERATOR(*, Long);
232229 IMPLEMENT_BINARY_OPERATOR(*, Float);
233230 IMPLEMENT_BINARY_OPERATOR(*, Double);
234 IMPLEMENT_BINARY_OPERATOR(*, Pointer);
235 default:
236 cout << "Unhandled type for Mul instruction: " << Ty << "\n";
231 default:
232 std::cout << "Unhandled type for Mul instruction: " << Ty << "\n";
233 abort();
237234 }
238235 return Dest;
239236 }
252249 IMPLEMENT_BINARY_OPERATOR(/, Long);
253250 IMPLEMENT_BINARY_OPERATOR(/, Float);
254251 IMPLEMENT_BINARY_OPERATOR(/, Double);
255 IMPLEMENT_BINARY_OPERATOR(/, Pointer);
256 default:
257 cout << "Unhandled type for Div instruction: " << Ty << "\n";
252 default:
253 std::cout << "Unhandled type for Div instruction: " << *Ty << "\n";
254 abort();
258255 }
259256 return Dest;
260257 }
271268 IMPLEMENT_BINARY_OPERATOR(%, Int);
272269 IMPLEMENT_BINARY_OPERATOR(%, ULong);
273270 IMPLEMENT_BINARY_OPERATOR(%, Long);
274 IMPLEMENT_BINARY_OPERATOR(%, Pointer);
275271 case Type::FloatTyID:
276272 Dest.FloatVal = fmod(Src1.FloatVal, Src2.FloatVal);
277273 break;
279275 Dest.DoubleVal = fmod(Src1.DoubleVal, Src2.DoubleVal);
280276 break;
281277 default:
282 cout << "Unhandled type for Rem instruction: " << Ty << "\n";
278 std::cout << "Unhandled type for Rem instruction: " << *Ty << "\n";
279 abort();
283280 }
284281 return Dest;
285282 }
296293 IMPLEMENT_BINARY_OPERATOR(&, Int);
297294 IMPLEMENT_BINARY_OPERATOR(&, ULong);
298295 IMPLEMENT_BINARY_OPERATOR(&, Long);
299 IMPLEMENT_BINARY_OPERATOR(&, Pointer);
300 default:
301 cout << "Unhandled type for And instruction: " << Ty << "\n";
296 default:
297 std::cout << "Unhandled type for And instruction: " << *Ty << "\n";
298 abort();
302299 }
303300 return Dest;
304301 }
316313 IMPLEMENT_BINARY_OPERATOR(|, Int);
317314 IMPLEMENT_BINARY_OPERATOR(|, ULong);
318315 IMPLEMENT_BINARY_OPERATOR(|, Long);
319 IMPLEMENT_BINARY_OPERATOR(|, Pointer);
320 default:
321 cout << "Unhandled type for Or instruction: " << Ty << "\n";
316 default:
317 std::cout << "Unhandled type for Or instruction: " << *Ty << "\n";
318 abort();
322319 }
323320 return Dest;
324321 }
336333 IMPLEMENT_BINARY_OPERATOR(^, Int);
337334 IMPLEMENT_BINARY_OPERATOR(^, ULong);
338335 IMPLEMENT_BINARY_OPERATOR(^, Long);
339 IMPLEMENT_BINARY_OPERATOR(^, Pointer);
340 default:
341 cout << "Unhandled type for Xor instruction: " << Ty << "\n";
336 default:
337 std::cout << "Unhandled type for Xor instruction: " << *Ty << "\n";
338 abort();
342339 }
343340 return Dest;
344341 }
363360 IMPLEMENT_SETCC(==, Double);
364361 IMPLEMENT_SETCC(==, Pointer);
365362 default:
366 cout << "Unhandled type for SetEQ instruction: " << Ty << "\n";
363 std::cout << "Unhandled type for SetEQ instruction: " << *Ty << "\n";
364 abort();
367365 }
368366 return Dest;
369367 }
385383 IMPLEMENT_SETCC(!=, Pointer);
386384
387385 default:
388 cout << "Unhandled type for SetNE instruction: " << Ty << "\n";
386 std::cout << "Unhandled type for SetNE instruction: " << *Ty << "\n";
387 abort();
389388 }
390389 return Dest;
391390 }
406405 IMPLEMENT_SETCC(<=, Double);
407406 IMPLEMENT_SETCC(<=, Pointer);
408407 default:
409 cout << "Unhandled type for SetLE instruction: " << Ty << "\n";
408 std::cout << "Unhandled type for SetLE instruction: " << Ty << "\n";
409 abort();
410410 }
411411 return Dest;
412412 }
427427 IMPLEMENT_SETCC(>=, Double);
428428 IMPLEMENT_SETCC(>=, Pointer);
429429 default:
430 cout << "Unhandled type for SetGE instruction: " << Ty << "\n";
430 std::cout << "Unhandled type for SetGE instruction: " << *Ty << "\n";
431 abort();
431432 }
432433 return Dest;
433434 }
448449 IMPLEMENT_SETCC(<, Double);
449450 IMPLEMENT_SETCC(<, Pointer);
450451 default:
451 cout << "Unhandled type for SetLT instruction: " << Ty << "\n";
452 std::cout << "Unhandled type for SetLT instruction: " << *Ty << "\n";
453 abort();
452454 }
453455 return Dest;
454456 }
469471 IMPLEMENT_SETCC(>, Double);
470472 IMPLEMENT_SETCC(>, Pointer);
471473 default:
472 cout << "Unhandled type for SetGT instruction: " << Ty << "\n";
474 std::cout << "Unhandled type for SetGT instruction: " << *Ty << "\n";
475 abort();
473476 }
474477 return Dest;
475478 }
496499 case Instruction::SetLT: R = executeSetLTInst(Src1, Src2, Ty); break;
497500 case Instruction::SetGT: R = executeSetGTInst(Src1, Src2, Ty); break;
498501 default:
499 cout << "Don't know how to handle this binary operator!\n-->" << I;
500 R = Src1;
502 std::cout << "Don't know how to handle this binary operator!\n-->" << I;
503 abort();
501504 }
502505
503506 SetValue(&I, R, SF);
512515 // Print out structure field accounting information...
513516 if (!FieldAccessCounts.empty()) {
514517 CW << "Profile Field Access Counts:\n";
515 std::mapvector >::iterator
518 std::mapstd::vector >::iterator
516519 I = FieldAccessCounts.begin(), E = FieldAccessCounts.end();
517520 for (; I != E; ++I) {
518 vector &OfC = I->second;
521 std::vector &OfC = I->second;
519522 CW << " '" << (Value*)I->first << "'\t- Sum=";
520523
521524 unsigned Sum = 0;
532535 CW << "\n";
533536
534537 CW << "Profile Field Access Percentages:\n";
535 cout.precision(3);
538 std::cout.precision(3);
536539 for (I = FieldAccessCounts.begin(); I != E; ++I) {
537 vector &OfC = I->second;
540 std::vector &OfC = I->second;
538541 unsigned Sum = 0;
539542 for (unsigned i = 0; i < OfC.size(); ++i)
540543 Sum += OfC[i];
555558
556559 void Interpreter::exitCalled(GenericValue GV) {
557560 if (!QuietMode) {
558 cout << "Program returned ";
561 std::cout << "Program returned ";
559562 print(Type::IntTy, GV);
560 cout << " via 'void exit(int)'\n";
563 std::cout << " via 'void exit(int)'\n";
561564 }
562565
563566 ExitCode = GV.SByteVal;
587590 CW << "Function " << M->getType() << " \"" << M->getName()
588591 << "\" returned ";
589592 print(RetTy, Result);
590 cout << "\n";
593 std::cout << "\n";
591594 }
592595
593596 if (RetTy->isIntegral())
615618 CW << "Function " << M->getType() << " \"" << M->getName()
616619 << "\" returned ";
617620 print(RetTy, Result);
618 cout << "\n";
621 std::cout << "\n";
619622 }
620623 }
621624
708711 #ifdef PROFILE_STRUCTURE_FIELDS
709712 if (ProfileStructureFields) {
710713 // Do accounting for this field...
711 vector &OfC = FieldAccessCounts[STy];
714 std::vector &OfC = FieldAccessCounts[STy];
712715 if (OfC.size() == 0) OfC.resize(STy->getElementTypes().size());
713716 OfC[Index]++;
714717 }
723726 unsigned Idx = getOperandValue(*I, SF).LongVal;
724727 if (const ArrayType *AT = dyn_cast(ST))
725728 if (Idx >= AT->getNumElements() && ArrayChecksEnabled) {
726 cerr << "Out of range memory access to element #" << Idx
727 << " of a " << AT->getNumElements() << " element array."
728 << " Subscript #" << *I << "\n";
729 std::cerr << "Out of range memory access to element #" << Idx
730 << " of a " << AT->getNumElements() << " element array."
731 << " Subscript #" << *I << "\n";
729732 // Get outta here!!!
730733 siglongjmp(SignalRecoverBuffer, SIGTRAP);
731734 }
780783 ((uint64_t)Ptr->Untyped[7] << 56);
781784 break;
782785 default:
783 cout << "Cannot load value of type " << I.getType() << "!\n";
786 std::cout << "Cannot load value of type " << *I.getType() << "!\n";
787 abort();
784788 }
785789 } else {
786790 switch (I.getType()->getPrimitiveID()) {
811815 ((uint64_t)Ptr->Untyped[0] << 56);
812816 break;
813817 default:
814 cout << "Cannot load value of type " << I.getType() << "!\n";
818 std::cout << "Cannot load value of type " << *I.getType() << "!\n";
819 abort();
815820 }
816821 }
817822
833838
834839 void Interpreter::executeCallInst(CallInst &I, ExecutionContext &SF) {
835840 ECStack.back().Caller = &I;
836 vector ArgVals;
841 std::vector ArgVals;
837842 ArgVals.reserve(I.getNumOperands()-1);
838843 for (unsigned i = 1; i < I.getNumOperands(); ++i) {
839844 ArgVals.push_back(getOperandValue(I.getOperand(i), SF));
900905 IMPLEMENT_SHIFT(<<, Int);
901906 IMPLEMENT_SHIFT(<<, ULong);
902907 IMPLEMENT_SHIFT(<<, Long);
903 IMPLEMENT_SHIFT(<<, Pointer);
904 default:
905 cout << "Unhandled type for Shl instruction: " << Ty << "\n";
908 default:
909 std::cout << "Unhandled type for Shl instruction: " << *Ty << "\n";
906910 }
907911 SetValue(&I, Dest, SF);
908912 }
922926 IMPLEMENT_SHIFT(>>, Int);
923927 IMPLEMENT_SHIFT(>>, ULong);
924928 IMPLEMENT_SHIFT(>>, Long);
925 IMPLEMENT_SHIFT(>>, Pointer);
926 default:
927 cout << "Unhandled type for Shr instruction: " << Ty << "\n";
929 default:
930 std::cout << "Unhandled type for Shr instruction: " << *Ty << "\n";
931 abort();
928932 }
929933 SetValue(&I, Dest, SF);
930934 }
951955 IMPLEMENT_CAST(DESTTY, DESTCTY, Double)
952956
953957 #define IMPLEMENT_CAST_CASE_END() \
954 default: cout << "Unhandled cast: " << SrcTy << " to " << Ty << "\n"; \
955 break; \
958 default: std::cout << "Unhandled cast: " << SrcTy << " to " << Ty << "\n"; \
959 abort(); \
956960 } \
957961 break
958962
980984 IMPLEMENT_CAST_CASE(Double , (double));
981985 IMPLEMENT_CAST_CASE(Bool , (bool));
982986 default:
983 cout << "Unhandled dest type for cast instruction: " << Ty << "\n";
987 std::cout << "Unhandled dest type for cast instruction: " << *Ty << "\n";
984988 abort();
985989 }
986990
10211025 //===----------------------------------------------------------------------===//
10221026 // callMethod - Execute the specified function...
10231027 //
1024 void Interpreter::callMethod(Function *M, const vector &ArgVals) {
1028 void Interpreter::callMethod(Function *M,
1029 const std::vector &ArgVals) {
10251030 assert((ECStack.empty() || ECStack.back().Caller == 0 ||
10261031 ECStack.back().Caller->getNumOperands()-1 == ArgVals.size()) &&
10271032 "Incorrect number of arguments passed into function call!");
10421047 CW << "Function " << M->getType() << " \"" << M->getName()
10431048 << "\" returned ";
10441049 print(RetTy, Result);
1045 cout << "\n";
1050 std::cout << "\n";
10461051
10471052 if (RetTy->isIntegral())
10481053 ExitCode = Result.IntVal; // Capture the exit code of the program
11071112 if (int SigNo = sigsetjmp(SignalRecoverBuffer, 1)) {
11081113 --SF.CurInst; // Back up to erroring instruction
11091114 if (SigNo != SIGINT) {
1110 cout << "EXCEPTION OCCURRED [" << strsignal(SigNo) << "]:\n";
1115 std::cout << "EXCEPTION OCCURRED [" << strsignal(SigNo) << "]:\n";
11111116 printStackTrace();
11121117 // If -abort-on-exception was specified, terminate LLI instead of trying
11131118 // to debug it.
11141119 //
11151120 if (AbortOnExceptions) exit(1);
11161121 } else if (SigNo == SIGINT) {
1117 cout << "CTRL-C Detected, execution halted.\n";
1122 std::cout << "CTRL-C Detected, execution halted.\n";
11181123 }
11191124 InInstruction = false;
11201125 return true;
11451150 case Instruction::Shr: executeShrInst (cast(I), SF); break;
11461151 case Instruction::Cast: executeCastInst (cast (I), SF); break;
11471152 default:
1148 cout << "Don't know how to execute this instruction!\n-->" << I;
1153 std::cout << "Don't know how to execute this instruction!\n-->" << I;
1154 abort();
11491155 }
11501156 }
11511157 InInstruction = false;
11611167
11621168 void Interpreter::stepInstruction() { // Do the 'step' command
11631169 if (ECStack.empty()) {
1164 cout << "Error: no program running, cannot step!\n";
1170 std::cout << "Error: no program running, cannot step!\n";
11651171 return;
11661172 }
11671173
11751181 // --- UI Stuff...
11761182 void Interpreter::nextInstruction() { // Do the 'next' command
11771183 if (ECStack.empty()) {
1178 cout << "Error: no program running, cannot 'next'!\n";
1184 std::cout << "Error: no program running, cannot 'next'!\n";
11791185 return;
11801186 }
11811187
11861192 // Step into the function...
11871193 if (executeInstruction()) {
11881194 // Hit a breakpoint, print current instruction, then return to user...
1189 cout << "Breakpoint hit!\n";
1195 std::cout << "Breakpoint hit!\n";
11901196 printCurrentInstruction();
11911197 return;
11921198 }
12061212
12071213 void Interpreter::run() {
12081214 if (ECStack.empty()) {
1209 cout << "Error: no program running, cannot run!\n";
1215 std::cout << "Error: no program running, cannot run!\n";
12101216 return;
12111217 }
12121218
12161222 HitBreakpoint = executeInstruction();
12171223 }
12181224
1219 if (HitBreakpoint) {
1220 cout << "Breakpoint hit!\n";
1221 }
1225 if (HitBreakpoint)
1226 std::cout << "Breakpoint hit!\n";
1227
12221228 // Print the next instruction to execute...
12231229 printCurrentInstruction();
12241230 }
12251231
12261232 void Interpreter::finish() {
12271233 if (ECStack.empty()) {
1228 cout << "Error: no program running, cannot run!\n";
1234 std::cout << "Error: no program running, cannot run!\n";
12291235 return;
12301236 }
12311237
12361242 HitBreakpoint = executeInstruction();
12371243 }
12381244
1239 if (HitBreakpoint) {
1240 cout << "Breakpoint hit!\n";
1241 }
1245 if (HitBreakpoint)
1246 std::cout << "Breakpoint hit!\n";
12421247
12431248 // Print the next instruction to execute...
12441249 printCurrentInstruction();
12521257 void Interpreter::printCurrentInstruction() {
12531258 if (!ECStack.empty()) {
12541259 if (ECStack.back().CurBB->begin() == ECStack.back().CurInst) // print label
1255 WriteAsOperand(cout, ECStack.back().CurBB) << ":\n";
1260 WriteAsOperand(std::cout, ECStack.back().CurBB) << ":\n";
12561261
12571262 Instruction &I = *ECStack.back().CurInst;
12581263 InstNumber *IN = (InstNumber*)I.getAnnotation(SlotNumberAID);
12591264 assert(IN && "Instruction has no numbering annotation!");
1260 cout << "#" << IN->InstNum << I;
1265 std::cout << "#" << IN->InstNum << I;
12611266 }
12621267 }
12631268
12641269 void Interpreter::printValue(const Type *Ty, GenericValue V) {
12651270 switch (Ty->getPrimitiveID()) {
1266 case Type::BoolTyID: cout << (V.BoolVal?"true":"false"); break;
1271 case Type::BoolTyID: std::cout << (V.BoolVal?"true":"false"); break;
12671272 case Type::SByteTyID:
1268 cout << (int)V.SByteVal << " '" << V.SByteVal << "'"; break;
1273 std::cout << (int)V.SByteVal << " '" << V.SByteVal << "'"; break;
12691274 case Type::UByteTyID:
1270 cout << (unsigned)V.UByteVal << " '" << V.UByteVal << "'"; break;
1271 case Type::ShortTyID: cout << V.ShortVal; break;
1272 case Type::UShortTyID: cout << V.UShortVal; break;
1273 case Type::IntTyID: cout << V.IntVal; break;
1274 case Type::UIntTyID: cout << V.UIntVal; break;
1275 case Type::LongTyID: cout << (long)V.LongVal; break;
1276 case Type::ULongTyID: cout << (unsigned long)V.ULongVal; break;
1277 case Type::FloatTyID: cout << V.FloatVal; break;
1278 case Type::DoubleTyID: cout << V.DoubleVal; break;
1279 case Type::PointerTyID:cout << (void*)GVTOP(V); break;
1280 default:
1281 cout << "- Don't know how to print value of this type!";
1275 std::cout << (unsigned)V.UByteVal << " '" << V.UByteVal << "'"; break;
1276 case Type::ShortTyID: std::cout << V.ShortVal; break;
1277 case Type::UShortTyID: std::cout << V.UShortVal; break;
1278 case Type::IntTyID: std::cout << V.IntVal; break;
1279 case Type::UIntTyID: std::cout << V.UIntVal; break;
1280 case Type::LongTyID: std::cout << (long)V.LongVal; break;
1281 case Type::ULongTyID: std::cout << (unsigned long)V.ULongVal; break;
1282 case Type::FloatTyID: std::cout << V.FloatVal; break;
1283 case Type::DoubleTyID: std::cout << V.DoubleVal; break;
1284 case Type::PointerTyID:std::cout << (void*)GVTOP(V); break;
1285 default:
1286 std::cout << "- Don't know how to print value of this type!";
12821287 break;
12831288 }
12841289 }
13011306 } else { // Otherwise there should be an annotation for the slot#
13021307 print(PickedVal->getType(),
13031308 getOperandValue(PickedVal, ECStack[CurFrame]));
1304 cout << "\n";
1309 std::cout << "\n";
13051310 }
13061311 }
13071312
13091314 Value *PickedVal = ChooseOneOption(Name, LookupMatchingNames(Name));
13101315 if (!PickedVal) return;
13111316
1312 cout << "Value: ";
1317 std::cout << "Value: ";
13131318 print(PickedVal->getType(),
13141319 getOperandValue(PickedVal, ECStack[CurFrame]));
1315 cout << "\n";
1320 std::cout << "\n";
13161321 printOperandInfo(PickedVal, ECStack[CurFrame]);
13171322 }
13181323
13291334
13301335 unsigned i = 0;
13311336 for (Function::aiterator I = F->abegin(), E = F->aend(); I != E; ++I, ++i) {
1332 if (i != 0) cout << ", ";
1337 if (i != 0) std::cout << ", ";
13331338 CW << *I << "=";
13341339
13351340 printValue(I->getType(), getOperandValue(I, ECStack[FrameNo]));
13361341 }
13371342
1338 cout << ")\n";
1343 std::cout << ")\n";
13391344
13401345 if (FrameNo != int(ECStack.size()-1)) {
13411346 BasicBlock::iterator I = ECStack[FrameNo].CurInst;