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

Unified Diff: src/PNaClTranslator.cpp

Issue 1378163002: Add check to verify alignment on global variables. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Fix nits. 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/bad-global-alignment.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 ba9eabbd7265ad6b62e5e68ff5c813e3794b5f06..0493386a06f0742e98f18867fad6b919a875fdab 100644
--- a/src/PNaClTranslator.cpp
+++ b/src/PNaClTranslator.cpp
@@ -352,6 +352,28 @@ public:
return std::move(VariableDeclarations);
}
+ // Upper limit of alignment power allowed by LLVM
+ static const uint32_t AlignPowerLimit = 29;
Jim Stichnoth 2015/09/30 21:40:21 constexpr ?
Karl 2015/09/30 22:23:45 Done.
+
+ // Extracts the corresponding Alignment to use, given the AlignPower (i.e.
+ // 2**(AlignPower-1), or 0 if AlignPower == 0). Parser defines the block
+ // context the alignment check appears in, and Prefix defines the context the
+ // alignment appears in.
+ void extractAlignment(NaClBitcodeParser *Parser, const char *Prefix,
Jim Stichnoth 2015/09/30 21:40:21 Can this function directly return Alignment instea
Karl 2015/09/30 22:23:45 Done.
+ uint32_t AlignPower, uint32_t &Alignment) {
+ if (AlignPower <= AlignPowerLimit + 1) {
+ Alignment = (1 << AlignPower) >> 1;
+ return;
+ }
+ std::string Buffer;
+ raw_string_ostream StrBuf(Buffer);
+ StrBuf << Prefix << " alignment greater than 2**" << AlignPowerLimit
+ << ". Found: 2**" << (AlignPower - 1);
+ Parser->Error(StrBuf.str());
+ // Error recover with value that is always acceptable.
+ Alignment = 1;
+ }
+
private:
// The translator associated with the parser.
Ice::Translator &Translator;
@@ -1061,10 +1083,12 @@ void GlobalsParser::ProcessRecord() {
// Always build the global variable, even if IR generation is turned off.
// This is needed because we need a placeholder in the top-level context
// when no IR is generated.
+ uint32_t Alignment;
+ Context->extractAlignment(this, "Global variable", Values[0], Alignment);
CurGlobalVar = getGlobalVarByID(NextGlobalID);
if (!isIRGenerationDisabled()) {
InitializersNeeded = 1;
- CurGlobalVar->setAlignment((1 << Values[0]) >> 1);
+ CurGlobalVar->setAlignment(Alignment);
CurGlobalVar->setIsConstant(Values[1] != 0);
}
++NextGlobalID;
@@ -1381,26 +1405,6 @@ private:
NaClBcIndexSize_t NextLocalInstIndex;
// True if the last processed instruction was a terminating instruction.
bool InstIsTerminating = false;
- // Upper limit of alignment power allowed by LLVM
- static const uint32_t AlignPowerLimit = 29;
-
- // Extracts the corresponding Alignment to use, given the AlignPower (i.e.
- // 2**(AlignPower-1), or 0 if AlignPower == 0). InstName is the name of the
- // instruction the alignment appears in.
- void extractAlignment(const char *InstName, uint32_t AlignPower,
- uint32_t &Alignment) {
- if (AlignPower <= AlignPowerLimit + 1) {
- Alignment = (1 << AlignPower) >> 1;
- return;
- }
- std::string Buffer;
- raw_string_ostream StrBuf(Buffer);
- StrBuf << InstName << " alignment greater than 2**" << AlignPowerLimit
- << ". Found: 2**" << (AlignPower - 1);
- Error(StrBuf.str());
- // Error recover with value that is always acceptable.
- Alignment = 1;
- }
bool ParseBlock(unsigned BlockID) override;
@@ -2593,7 +2597,7 @@ void FunctionParser::ProcessRecord() {
return;
Ice::Operand *ByteCount = getRelativeOperand(Values[0], BaseIndex);
uint32_t Alignment;
- extractAlignment("Alloca", Values[1], Alignment);
+ Context->extractAlignment(this, "Alloca", Values[1], Alignment);
if (isIRGenerationDisabled()) {
assert(ByteCount == nullptr);
setNextLocalInstIndex(nullptr);
@@ -2619,7 +2623,7 @@ void FunctionParser::ProcessRecord() {
Ice::Operand *Address = getRelativeOperand(Values[0], BaseIndex);
Ice::Type Ty = Context->getSimpleTypeByID(Values[2]);
uint32_t Alignment;
- extractAlignment("Load", Values[1], Alignment);
+ Context->extractAlignment(this, "Load", Values[1], Alignment);
if (isIRGenerationDisabled()) {
assert(Address == nullptr);
setNextLocalInstIndex(nullptr);
@@ -2644,7 +2648,7 @@ void FunctionParser::ProcessRecord() {
Ice::Operand *Address = getRelativeOperand(Values[0], BaseIndex);
Ice::Operand *Value = getRelativeOperand(Values[1], BaseIndex);
uint32_t Alignment;
- extractAlignment("Store", Values[2], Alignment);
+ Context->extractAlignment(this, "Store", Values[2], Alignment);
if (isIRGenerationDisabled()) {
assert(Address == nullptr && Value == nullptr);
return;
« no previous file with comments | « no previous file | tests_lit/parse_errs/Inputs/bad-global-alignment.tbc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698