aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Seaborn <mseaborn@chromium.org>2013-04-12 12:56:57 -0700
committerMark Seaborn <mseaborn@chromium.org>2013-04-12 12:56:57 -0700
commit14551e67a9ac4e521b9dd5f7776bb1a4fdcd7998 (patch)
tree02bce6162fc445f58fcca14515daba3181b5fe69
parenteb6ea25e95165fe6467512d759bbcf020e352351 (diff)
PNaCl ABI checker: Disallow ConstantExprs inside functions
BUG=https://code.google.com/p/nativeclient/issues/detail?id=3337 TEST=test/NaCl/PNaClABI/*.ll Review URL: https://codereview.chromium.org/13932023
-rw-r--r--lib/Analysis/NaCl/PNaClABIVerifyFunctions.cpp8
-rw-r--r--test/NaCl/PNaClABI/instructions.ll9
2 files changed, 17 insertions, 0 deletions
diff --git a/lib/Analysis/NaCl/PNaClABIVerifyFunctions.cpp b/lib/Analysis/NaCl/PNaClABIVerifyFunctions.cpp
index 54e2e19340..f96b45752b 100644
--- a/lib/Analysis/NaCl/PNaClABIVerifyFunctions.cpp
+++ b/lib/Analysis/NaCl/PNaClABIVerifyFunctions.cpp
@@ -173,6 +173,14 @@ bool PNaClABIVerifyFunctions::runOnFunction(Function &F) {
}
}
+ for (User::const_op_iterator OI = BBI->op_begin(), OE = BBI->op_end();
+ OI != OE; OI++) {
+ if (isa<ConstantExpr>(OI)) {
+ Reporter->addError() << "Function " << F.getName() <<
+ " contains disallowed ConstantExpr\n";
+ }
+ }
+
// Get types hiding in metadata attached to the instruction
SmallVector<std::pair<unsigned, MDNode*>, 4> MDForInst;
BBI->getAllMetadataOtherThanDebugLoc(MDForInst);
diff --git a/test/NaCl/PNaClABI/instructions.ll b/test/NaCl/PNaClABI/instructions.ll
index 968b47f6fc..2a1f7de386 100644
--- a/test/NaCl/PNaClABI/instructions.ll
+++ b/test/NaCl/PNaClABI/instructions.ll
@@ -123,6 +123,7 @@ onerror:
personality i8* bitcast (void ()* @personality_func to i8*)
catch i32* null
; CHECK-NEXT: Function invoke_func has disallowed instruction: landingpad
+; CHECK-NEXT: Function invoke_func contains disallowed ConstantExpr
ret void
}
@@ -133,5 +134,13 @@ define i32 @va_arg(i8* %va_list) {
; CHECK-NOT: disallowed
; CHECK: Function va_arg has disallowed instruction: va_arg
+@global_var = global i32 0
+
+define i32* @constantexpr() {
+ ret i32* getelementptr (i32* @global_var, i32 1)
+}
+; CHECK-NOT: disallowed
+; CHECK: Function constantexpr contains disallowed ConstantExpr
+
; CHECK-NOT: disallowed
; If another check is added, there should be a check-not in between each check