aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/Analysis/NaCl/PNaClABIVerifyFunctions.cpp21
-rw-r--r--lib/Analysis/NaCl/PNaClABIVerifyModule.cpp15
2 files changed, 35 insertions, 1 deletions
diff --git a/lib/Analysis/NaCl/PNaClABIVerifyFunctions.cpp b/lib/Analysis/NaCl/PNaClABIVerifyFunctions.cpp
index 97278d95cc..ef1c26e175 100644
--- a/lib/Analysis/NaCl/PNaClABIVerifyFunctions.cpp
+++ b/lib/Analysis/NaCl/PNaClABIVerifyFunctions.cpp
@@ -15,7 +15,7 @@
#include "llvm/Pass.h"
#include "llvm/ADT/Twine.h"
#include "llvm/IR/Function.h"
-#include "llvm/IR/Instruction.h"
+#include "llvm/IR/Instructions.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Analysis/NaCl.h"
@@ -44,6 +44,7 @@ bool PNaClABIVerifyFunctions::runOnFunction(Function &F) {
// For now just start with new errors on each function; this may change
// once we want to do something with them other than just calling print()
ErrorsString.clear();
+ // TODO: only report one error per instruction
for (Function::const_iterator FI = F.begin(), FE = F.end();
FI != FE; ++FI) {
for (BasicBlock::const_iterator BBI = FI->begin(), BBE = FI->end();
@@ -128,6 +129,24 @@ bool PNaClABIVerifyFunctions::runOnFunction(Function &F) {
" has instruction with disallowed type: " +
PNaClABITypeChecker::getTypeName(BBI->getType()) + "\n";
}
+
+ // Check the instruction operands. Operands which are Instructions will
+ // be checked on their own here, and GlobalValues will be checked by the
+ // Module verifier. That leaves Constants.
+ // Switches are implemented in the in-memory IR with vectors, so don't
+ // check them.
+ if (!isa<SwitchInst>(*BBI))
+ for (User::const_op_iterator OI = BBI->op_begin(), OE = BBI->op_end();
+ OI != OE; OI++) {
+ if (isa<Constant>(OI) && !isa<GlobalValue>(OI) &&
+ !isa<Instruction>(OI)) {
+ Type *T = TC.checkTypesInValue(*OI);
+ if (T)
+ Errors << "Function " + F.getName() +
+ " has instruction operand with disallowed type: " +
+ PNaClABITypeChecker::getTypeName(T) + "\n";
+ }
+ }
}
}
diff --git a/lib/Analysis/NaCl/PNaClABIVerifyModule.cpp b/lib/Analysis/NaCl/PNaClABIVerifyModule.cpp
index 54666378b3..f2124e1d12 100644
--- a/lib/Analysis/NaCl/PNaClABIVerifyModule.cpp
+++ b/lib/Analysis/NaCl/PNaClABIVerifyModule.cpp
@@ -105,6 +105,21 @@ bool PNaClABIVerifyModule::runOnModule(Module &M) {
E = M.alias_end(); MI != E; ++MI)
Errors << "Variable " + MI->getName() + " is an alias (disallowed)\n";
+ for (Module::iterator MI = M.begin(), ME = M.end(); MI != ME; ++MI) {
+ // Check types of functions and their arguments
+ FunctionType *FT = MI->getFunctionType();
+ if (!TC.isValidType(FT->getReturnType()))
+ Errors << "Function " + MI->getName() + " has disallowed return type: " +
+ PNaClABITypeChecker::getTypeName(FT->getReturnType()) + "\n";
+ for (unsigned I = 0, E = FT->getNumParams(); I < E; ++I) {
+ Type *PT = FT->getParamType(I);
+ if (!TC.isValidType(PT))
+ Errors << "Function " << MI->getName() << " argument " << I + 1 <<
+ " has disallowed type: " <<
+ PNaClABITypeChecker::getTypeName(PT) + "\n";
+ }
+ }
+
Errors.flush();
return false;
}