Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Unified Diff: src/PNaClTranslator.cpp

Issue 1362643002: Fix pnacl-sz to not accept files containing multiple modules. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Fix nit. Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests_lit/parse_errs/Inputs/multiple-modules.tbc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/PNaClTranslator.cpp
diff --git a/src/PNaClTranslator.cpp b/src/PNaClTranslator.cpp
index 449332a3cbb6fe596457d6044b986b26426c8e9f..3380c9ea29e96de3cf26853b82db81407260bb7c 100644
--- a/src/PNaClTranslator.cpp
+++ b/src/PNaClTranslator.cpp
@@ -338,6 +338,9 @@ public:
return getGlobalVariableByID(Index - NumFunctionIds);
}
+ /// Returns true if a module block has been parsed.
+ bool parsedModuleBlock() const { return ParsedModuleBlock; }
+
/// Returns the list of parsed global variable declarations. Releases
/// ownership of the current list of global variables. Note: only returns
/// non-null pointer on first call. All successive calls return a null
@@ -374,6 +377,8 @@ private:
Ice::FuncSigType UndefinedFuncSigType;
// The block parser currently being applied. Used for error reporting.
BlockParserBaseClass *BlockParser = nullptr;
+ // Defines if a module block has already been parsed.
+ bool ParsedModuleBlock = false;
bool ParseBlock(unsigned BlockID) override;
@@ -3220,8 +3225,12 @@ void ModuleParser::ProcessRecord() {
bool TopLevelParser::ParseBlock(unsigned BlockID) {
if (BlockID == naclbitc::MODULE_BLOCK_ID) {
+ if (ParsedModuleBlock)
+ Fatal("Input can't contain more than one module");
ModuleParser Parser(BlockID, this);
- return Parser.ParseThisBlock();
+ bool ParseFailed = Parser.ParseThisBlock();
+ ParsedModuleBlock = true;
+ return ParseFailed;
}
// Generate error message by using default block implementation.
BlockParserBaseClass Parser(BlockID, this);
@@ -3248,14 +3257,13 @@ void PNaClTranslator::translate(const std::string &IRFilename,
// need a hook to tell the IceBrowserCompileServer to unblock its
// QueueStreamer.
// https://code.google.com/p/nativeclient/issues/detail?id=4163
- Ostream &ErrStream = getContext()->getStrError();
// Read header and verify it is good.
NaClBitcodeHeader Header;
if (Header.Read(MemObj.get())) {
llvm::report_fatal_error("Invalid PNaCl bitcode header");
}
if (!Header.IsSupported()) {
- ErrStream << Header.Unsupported();
+ getContext()->getStrError() << Header.Unsupported();
if (!Header.IsReadable()) {
llvm::report_fatal_error("Invalid PNaCl bitcode header");
}
@@ -3266,25 +3274,20 @@ void PNaClTranslator::translate(const std::string &IRFilename,
NaClBitstreamCursor InputStream(InputStreamFile);
TopLevelParser Parser(*this, InputStream, ErrorStatus);
- int TopLevelBlocks = 0;
while (!InputStream.AtEndOfStream()) {
if (Parser.Parse()) {
ErrorStatus.assign(EC_Bitcode);
return;
}
- ++TopLevelBlocks;
}
- if (TopLevelBlocks != 1) {
- ErrStream << IRFilename
- << ": Contains more than one module. Found: " << TopLevelBlocks
- << "\n";
- llvm::report_fatal_error("Bitcode has more than one module");
+ if (!Parser.parsedModuleBlock()) {
+ std::string Buffer;
+ raw_string_ostream StrBuf(Buffer);
+ StrBuf << IRFilename << ": Does not contain a module!";
+ llvm::report_fatal_error(StrBuf.str());
}
if (InputStreamFile.getBitcodeBytes().getExtent() % 4 != 0) {
- ErrStream
- << IRFilename
- << ": Bitcode stream should be a multiple of 4 bytes in length.\n";
llvm::report_fatal_error("Bitcode stream should be a multiple of 4 bytes");
}
}
« no previous file with comments | « no previous file | tests_lit/parse_errs/Inputs/multiple-modules.tbc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698