Index: lib/Analysis/NaCl/PNaClABIVerifyFunctions.cpp |
diff --git a/lib/Analysis/NaCl/PNaClABIVerifyFunctions.cpp b/lib/Analysis/NaCl/PNaClABIVerifyFunctions.cpp |
index cd3ede4b5872bc35a979aa18fbd9cec9f0eb8348..7b92b86a65a34beb6d4bda5429fb0605fa79d30d 100644 |
--- a/lib/Analysis/NaCl/PNaClABIVerifyFunctions.cpp |
+++ b/lib/Analysis/NaCl/PNaClABIVerifyFunctions.cpp |
@@ -17,6 +17,7 @@ |
#include "llvm/Analysis/NaCl.h" |
#include "llvm/IR/Function.h" |
#include "llvm/IR/Instructions.h" |
+#include "llvm/IR/LLVMContext.h" |
#include "llvm/IR/Metadata.h" |
#include "llvm/Support/raw_ostream.h" |
@@ -49,13 +50,27 @@ class PNaClABIVerifyFunctions : public FunctionPass { |
bool runOnFunction(Function &F); |
virtual void print(raw_ostream &O, const Module *M) const; |
private: |
+ bool IsWhitelistedMetadata(unsigned MDKind); |
PNaClABITypeChecker TC; |
PNaClABIErrorReporter *Reporter; |
bool ReporterIsOwned; |
}; |
+// There's no built-in way to get the name of an MDNode, so use a |
+// string ostream to print it. |
+std::string getMDNodeString(const MDNode *MD) { |
+ std::string s; |
+ raw_string_ostream N(s); |
+ MD->print(N); |
+ return N.str(); |
+} |
+ |
} // and anonymous namespace |
+bool PNaClABIVerifyFunctions::IsWhitelistedMetadata(unsigned MDKind) { |
+ return MDKind == LLVMContext::MD_dbg && llvm::PNaClABIAllowDebugMetadata; |
Derek Schuff
2013/04/26 00:34:34
llvm:: not necessary if using namespace llvm?
jvoung (off chromium)
2013/04/26 16:51:29
Done.
|
+} |
+ |
bool PNaClABIVerifyFunctions::runOnFunction(Function &F) { |
// TODO: only report one error per instruction? |
for (Function::const_iterator FI = F.begin(), FE = F.end(); |
@@ -181,15 +196,25 @@ bool PNaClABIVerifyFunctions::runOnFunction(Function &F) { |
} |
} |
- // Get types hiding in metadata attached to the instruction |
+ // Check instruction attachment metadata. |
SmallVector<std::pair<unsigned, MDNode*>, 4> MDForInst; |
- BBI->getAllMetadataOtherThanDebugLoc(MDForInst); |
+ BBI->getAllMetadata(MDForInst); |
+ |
for (unsigned i = 0, e = MDForInst.size(); i != e; i++) { |
- Type *T = TC.checkTypesInMDNode(MDForInst[i].second); |
- if (T) { |
- Reporter->addError() << "Function " << F.getName() << |
- " has instruction metadata containing disallowed type: " << |
- PNaClABITypeChecker::getTypeName(T) << "\n"; |
+ if (!IsWhitelistedMetadata(MDForInst[i].first)) { |
+ Reporter->addError() |
+ << "Function " << F.getName() |
+ << " has disallowed instruction metadata: " |
+ << getMDNodeString(MDForInst[i].second) << "\n"; |
+ } else { |
+ // If allowed, check the types hiding in the metadata. |
+ Type *T = TC.checkTypesInMDNode(MDForInst[i].second); |
+ if (T) { |
+ Reporter->addError() |
+ << "Function " << F.getName() |
+ << " has instruction metadata containing disallowed type: " |
+ << PNaClABITypeChecker::getTypeName(T) << "\n"; |
+ } |
} |
} |
} |