Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 //===- subzero/src/PNaClTranslator.cpp - ICE from bitcode -----------------===// | 1 //===- subzero/src/PNaClTranslator.cpp - ICE from bitcode -----------------===// |
| 2 // | 2 // |
| 3 // The Subzero Code Generator | 3 // The Subzero Code Generator |
| 4 // | 4 // |
| 5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
| 6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
| 7 // | 7 // |
| 8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
| 9 /// | 9 /// |
| 10 /// \file | 10 /// \file |
| (...skipping 1580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1591 // Checks if the type of operand Op is the valid pointer type, for the given | 1591 // Checks if the type of operand Op is the valid pointer type, for the given |
| 1592 // InstructionName. Returns true if valid. Otherwise generates an error | 1592 // InstructionName. Returns true if valid. Otherwise generates an error |
| 1593 // message and returns false. | 1593 // message and returns false. |
| 1594 bool isValidPointerType(Ice::Operand *Op, const char *InstructionName) { | 1594 bool isValidPointerType(Ice::Operand *Op, const char *InstructionName) { |
| 1595 Ice::Type PtrType = Ice::getPointerType(); | 1595 Ice::Type PtrType = Ice::getPointerType(); |
| 1596 if (Op->getType() == PtrType) | 1596 if (Op->getType() == PtrType) |
| 1597 return true; | 1597 return true; |
| 1598 std::string Buffer; | 1598 std::string Buffer; |
| 1599 raw_string_ostream StrBuf(Buffer); | 1599 raw_string_ostream StrBuf(Buffer); |
| 1600 StrBuf << InstructionName << " address not " << PtrType | 1600 StrBuf << InstructionName << " address not " << PtrType |
| 1601 << ". Found: " << *Op; | 1601 << ". Found: " << Op->getType(); |
| 1602 Error(StrBuf.str()); | 1602 Error(StrBuf.str()); |
| 1603 return false; | 1603 return false; |
| 1604 } | 1604 } |
| 1605 | 1605 |
| 1606 // Checks if loading/storing a value of type Ty is allowed. Returns true if | 1606 // Checks if loading/storing a value of type Ty is allowed. Returns true if |
| 1607 // Valid. Otherwise generates an error message and returns false. | 1607 // Valid. Otherwise generates an error message and returns false. |
| 1608 bool isValidLoadStoreType(Ice::Type Ty, const char *InstructionName) { | 1608 bool isValidLoadStoreType(Ice::Type Ty, const char *InstructionName) { |
| 1609 if (isLoadStoreType(Ty)) | 1609 if (isLoadStoreType(Ty)) |
| 1610 return true; | 1610 return true; |
| 1611 std::string Buffer; | 1611 std::string Buffer; |
| (...skipping 1043 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2655 if (!isValidRecordSizeAtLeast(2, "call")) | 2655 if (!isValidRecordSizeAtLeast(2, "call")) |
| 2656 return; | 2656 return; |
| 2657 } else { | 2657 } else { |
| 2658 if (!isValidRecordSizeAtLeast(3, "call indirect")) | 2658 if (!isValidRecordSizeAtLeast(3, "call indirect")) |
| 2659 return; | 2659 return; |
| 2660 ParamsStartIndex = 3; | 2660 ParamsStartIndex = 3; |
| 2661 } | 2661 } |
| 2662 | 2662 |
| 2663 // Extract out the called function and its return type. | 2663 // Extract out the called function and its return type. |
| 2664 uint32_t CalleeIndex = convertRelativeToAbsIndex(Values[1], BaseIndex); | 2664 uint32_t CalleeIndex = convertRelativeToAbsIndex(Values[1], BaseIndex); |
| 2665 Ice::Operand *Callee = getOperand(CalleeIndex); | 2665 Ice::Operand *Callee = getOperand(CalleeIndex); |
|
Jim Stichnoth
2015/09/23 20:40:06
Would it make sense to check Callee for valid type
Karl
2015/09/24 21:28:22
Type signatures are explicitly defined for direct
| |
| 2666 const Ice::FuncSigType *Signature = nullptr; | 2666 const Ice::FuncSigType *Signature = nullptr; |
| 2667 Ice::Type ReturnType = Ice::IceType_void; | 2667 Ice::Type ReturnType = Ice::IceType_void; |
| 2668 const Ice::Intrinsics::FullIntrinsicInfo *IntrinsicInfo = nullptr; | 2668 const Ice::Intrinsics::FullIntrinsicInfo *IntrinsicInfo = nullptr; |
| 2669 // Name of function if a direct call/intrinsic. Null otherwise. | 2669 // Name of function if a direct call/intrinsic. Null otherwise. |
| 2670 Ice::FunctionDeclaration *Fcn = nullptr; | 2670 Ice::FunctionDeclaration *Fcn = nullptr; |
| 2671 if (Record.GetCode() == naclbitc::FUNC_CODE_INST_CALL) { | 2671 if (Record.GetCode() == naclbitc::FUNC_CODE_INST_CALL) { |
| 2672 Fcn = Context->getFunctionByID(CalleeIndex); | 2672 Fcn = Context->getFunctionByID(CalleeIndex); |
| 2673 Signature = &Fcn->getSignature(); | 2673 Signature = &Fcn->getSignature(); |
| 2674 ReturnType = Signature->getReturnType(); | 2674 ReturnType = Signature->getReturnType(); |
| 2675 | 2675 |
| 2676 // Check if this direct call is to an Intrinsic (starts with "llvm.") | 2676 // Check if this direct call is to an Intrinsic (starts with "llvm.") |
| 2677 bool BadIntrinsic; | 2677 bool BadIntrinsic; |
| 2678 const Ice::IceString &Name = Fcn->getName(); | 2678 const Ice::IceString &Name = Fcn->getName(); |
| 2679 IntrinsicInfo = getTranslator().getContext()->getIntrinsicsInfo().find( | 2679 IntrinsicInfo = getTranslator().getContext()->getIntrinsicsInfo().find( |
| 2680 Name, BadIntrinsic); | 2680 Name, BadIntrinsic); |
| 2681 if (BadIntrinsic) { | 2681 if (BadIntrinsic) { |
| 2682 std::string Buffer; | 2682 std::string Buffer; |
| 2683 raw_string_ostream StrBuf(Buffer); | 2683 raw_string_ostream StrBuf(Buffer); |
| 2684 StrBuf << "Invalid PNaCl intrinsic call to " << Name; | 2684 StrBuf << "Invalid PNaCl intrinsic call to " << Name; |
| 2685 Error(StrBuf.str()); | 2685 Error(StrBuf.str()); |
| 2686 if (ReturnType != Ice::IceType_void) | 2686 if (ReturnType != Ice::IceType_void) |
| 2687 appendErrorInstruction(ReturnType); | 2687 appendErrorInstruction(ReturnType); |
| 2688 return; | 2688 return; |
| 2689 } | 2689 } |
| 2690 } else { | 2690 } else { |
| 2691 ReturnType = Context->getSimpleTypeByID(Values[2]); | 2691 ReturnType = Context->getSimpleTypeByID(Values[2]); |
| 2692 if (!isValidPointerType(Callee, "Call indirect")) { | |
| 2693 if (ReturnType != Ice::IceType_void) | |
| 2694 appendErrorInstruction(ReturnType); | |
|
Jim Stichnoth
2015/09/23 20:40:06
Should you return after this error? Or fall throu
Karl
2015/09/24 21:28:22
The code in general, should error recover if possi
| |
| 2695 } | |
| 2692 } | 2696 } |
| 2693 | 2697 |
| 2694 // Check return type. | 2698 // Check return type. |
| 2695 if (IntrinsicInfo == nullptr && !isCallReturnType(ReturnType)) { | 2699 if (IntrinsicInfo == nullptr && !isCallReturnType(ReturnType)) { |
| 2696 std::string Buffer; | 2700 std::string Buffer; |
| 2697 raw_string_ostream StrBuf(Buffer); | 2701 raw_string_ostream StrBuf(Buffer); |
| 2698 StrBuf << "Return type of called function is invalid: " << ReturnType; | 2702 StrBuf << "Return type of called function is invalid: " << ReturnType; |
| 2699 Error(StrBuf.str()); | 2703 Error(StrBuf.str()); |
| 2700 ReturnType = Ice::IceType_i32; | 2704 ReturnType = Ice::IceType_i32; |
| 2701 } | 2705 } |
| (...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3296 raw_string_ostream StrBuf(Buffer); | 3300 raw_string_ostream StrBuf(Buffer); |
| 3297 StrBuf << IRFilename << ": Does not contain a module!"; | 3301 StrBuf << IRFilename << ": Does not contain a module!"; |
| 3298 llvm::report_fatal_error(StrBuf.str()); | 3302 llvm::report_fatal_error(StrBuf.str()); |
| 3299 } | 3303 } |
| 3300 if (InputStreamFile.getBitcodeBytes().getExtent() % 4 != 0) { | 3304 if (InputStreamFile.getBitcodeBytes().getExtent() % 4 != 0) { |
| 3301 llvm::report_fatal_error("Bitcode stream should be a multiple of 4 bytes"); | 3305 llvm::report_fatal_error("Bitcode stream should be a multiple of 4 bytes"); |
| 3302 } | 3306 } |
| 3303 } | 3307 } |
| 3304 | 3308 |
| 3305 } // end of namespace Ice | 3309 } // end of namespace Ice |
| OLD | NEW |