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

Unified Diff: lib/Bitcode/NaCl/Reader/NaClBitcodeReader.h

Issue 807643002: Don't allow instructions/globals to use alignment > 2**29. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-llvm.git@master
Patch Set: Fix nit and add test cases. Created 6 years 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
Index: lib/Bitcode/NaCl/Reader/NaClBitcodeReader.h
diff --git a/lib/Bitcode/NaCl/Reader/NaClBitcodeReader.h b/lib/Bitcode/NaCl/Reader/NaClBitcodeReader.h
index 2ea3ede537487445e316d07ba13a815dfb2067ca..fa79eabc6f76d2fe1429d3d2751192775417eaac 100644
--- a/lib/Bitcode/NaCl/Reader/NaClBitcodeReader.h
+++ b/lib/Bitcode/NaCl/Reader/NaClBitcodeReader.h
@@ -16,6 +16,7 @@
#define NACL_BITCODE_READER_H
#include "llvm/ADT/DenseMap.h"
+#include "llvm/Analysis/NaCl/PNaClABIProps.h"
#include "llvm/Analysis/NaCl/PNaClAllowedIntrinsics.h"
#include "llvm/Bitcode/NaCl/NaClBitcodeHeader.h"
#include "llvm/Bitcode/NaCl/NaClBitstreamReader.h"
@@ -27,6 +28,7 @@
#include "llvm/IR/OperandTraits.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/ValueHandle.h"
+#include "llvm/Support/raw_ostream.h"
#include <vector>
namespace llvm {
@@ -248,6 +250,11 @@ public:
/// @returns true if an error occurred.
std::error_code ParseBitcodeInto(Module *M);
+ /// Convert alignment exponent (i.e. power of two (or zero)) to the
+ /// corresponding alignment to use. If alignment is too large, it generates
+ /// an error message and returns corresponding error code.
+ std::error_code getAlignmentValue(uint64_t Exponent, unsigned &Alignment);
+
private:
// Returns false if Header is acceptable.
bool AcceptHeader() const {
@@ -300,6 +307,27 @@ private:
return getFnValueByID(ValNo);
}
+ /// Convert alignment exponent (i.e. power of two (or zero)) to the
+ /// corresponding load/store alignment to use. If alignment is not
+ /// allowed for the load/store, it generates an error message and
+ /// returns the corresponding error code.
+ std::error_code getLoadStoreAlignmentValue(
+ uint64_t Exponent, const DataLayout *DL, Type *MemType,
+ const char *InstName, unsigned &Alignment) {
+ std::error_code EC = getAlignmentValue(Exponent, Alignment);
+ if (EC)
+ return EC;
+ if (!PNaClABIProps::isAllowedAlignment(DL, Alignment, MemType)) {
+ std::string Buffer;
+ raw_string_ostream StrBuf(Buffer);
+ StrBuf << "Invalid alignment for " << InstName << " of type "
+ << *MemType << ": " << Alignment;
+ return Error(InvalidValue, StrBuf.str());
+ }
+ // Successful!
+ return EC;
+ }
+
/// \brief Create an (elided) cast instruction for basic block
/// BBIndex. Op is the type of cast. V is the value to cast. CT
/// is the type to convert V to. DeferInsertion defines whether the
« no previous file with comments | « no previous file | lib/Bitcode/NaCl/Reader/NaClBitcodeReader.cpp » ('j') | lib/Bitcode/NaCl/Reader/NaClBitcodeReader.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698