diff options
author | Derek Schuff <dschuff@chromium.org> | 2013-01-18 14:41:11 -0800 |
---|---|---|
committer | Derek Schuff <dschuff@chromium.org> | 2013-01-18 14:41:11 -0800 |
commit | 958cd97d295ba41736615e33c4a1aa641989133e (patch) | |
tree | 3c47d5f6482709973da6136e84181e3546145c4a | |
parent | afd5ec31850faae645dabe3f83f869643cd7b0c5 (diff) |
Move ABI verifier pass declaration to lib/Analysis and add tests
This fixes the move of the verifier passes from lib/Transforms to
lib/Analysis, and adds tests of the current verifier checks.
No new functionality.
R=jvoung@chromium.org,eliben@chromium.org,mseaborn@chromium.org
BUG= https://code.google.com/p/nativeclient/issues/detail?id=2196
Review URL: https://codereview.chromium.org/12017019
-rw-r--r-- | include/llvm/Analysis/NaCl.h | 23 | ||||
-rw-r--r-- | include/llvm/Transforms/NaCl.h | 3 | ||||
-rw-r--r-- | lib/Analysis/NaCl/PNaClABIVerifyFunctions.cpp | 13 | ||||
-rw-r--r-- | lib/Analysis/NaCl/PNaClABIVerifyModule.cpp | 11 | ||||
-rw-r--r-- | test/NaCl/PNaClABI/instructions.ll | 20 | ||||
-rw-r--r-- | test/NaCl/PNaClABI/linkagetypes.ll | 37 | ||||
-rw-r--r-- | test/NaCl/PNaClABI/lit.local.cfg | 1 |
7 files changed, 98 insertions, 10 deletions
diff --git a/include/llvm/Analysis/NaCl.h b/include/llvm/Analysis/NaCl.h new file mode 100644 index 0000000000..5f8c534c6f --- /dev/null +++ b/include/llvm/Analysis/NaCl.h @@ -0,0 +1,23 @@ +//===-- NaCl.h - NaCl Analysis ---------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_ANALYSIS_NACL_H +#define LLVM_ANALYSIS_NACL_H + +namespace llvm { + +class FunctionPass; +class ModulePass; + +FunctionPass *createPNaClABIVerifyFunctionsPass(); +ModulePass *createPNaClABIVerifyModulePass(); + +} + +#endif diff --git a/include/llvm/Transforms/NaCl.h b/include/llvm/Transforms/NaCl.h index ecdfa9043f..79c9b9fe79 100644 --- a/include/llvm/Transforms/NaCl.h +++ b/include/llvm/Transforms/NaCl.h @@ -12,14 +12,11 @@ namespace llvm { -class FunctionPass; class ModulePass; ModulePass *createExpandCtorsPass(); ModulePass *createExpandTlsPass(); ModulePass *createExpandTlsConstantExprPass(); -FunctionPass *createPNaClABIVerifyFunctionsPass(); -ModulePass *createPNaClABIVerifyModulePass(); } diff --git a/lib/Analysis/NaCl/PNaClABIVerifyFunctions.cpp b/lib/Analysis/NaCl/PNaClABIVerifyFunctions.cpp index a2e5f1b2a5..abc66b0add 100644 --- a/lib/Analysis/NaCl/PNaClABIVerifyFunctions.cpp +++ b/lib/Analysis/NaCl/PNaClABIVerifyFunctions.cpp @@ -17,7 +17,7 @@ #include "llvm/Instruction.h" #include "llvm/Pass.h" #include "llvm/Support/raw_ostream.h" -#include "llvm/Transforms/NaCl.h" +#include "llvm/Analysis/NaCl.h" using namespace llvm; namespace { @@ -28,6 +28,11 @@ struct PNaClABIVerifyFunctions : public FunctionPass { static char ID; PNaClABIVerifyFunctions() : FunctionPass(ID) {} bool runOnFunction(Function &F); + // For now, this print method exists to allow us to run the pass with + // opt -analyze to avoid dumping the result to stdout, to make testing + // simpler. In the future we will probably want to make it do something + // useful. + virtual void print(llvm::raw_ostream &O, const Module *M) const {}; }; } // and anonymous namespace @@ -47,8 +52,8 @@ bool PNaClABIVerifyFunctions::runOnFunction(Function &F) { // invoke and call are handled separately. break; default: - errs() << Twine("Function ") + FI->getName() + - " has Disallowed instruction: " + + errs() << Twine("Function ") + F.getName() + + " has disallowed instruction: " + BBI->getOpcodeName() + "\n"; } } @@ -58,7 +63,7 @@ bool PNaClABIVerifyFunctions::runOnFunction(Function &F) { char PNaClABIVerifyFunctions::ID = 0; -static RegisterPass<PNaClABIVerifyFunctions> X("pnaclabi-functions", +static RegisterPass<PNaClABIVerifyFunctions> X("verify-pnaclabi-functions", "Verify functions for PNaCl", false, false); FunctionPass *llvm::createPNaClABIVerifyFunctionsPass() { diff --git a/lib/Analysis/NaCl/PNaClABIVerifyModule.cpp b/lib/Analysis/NaCl/PNaClABIVerifyModule.cpp index f39b83881e..5062f710f6 100644 --- a/lib/Analysis/NaCl/PNaClABIVerifyModule.cpp +++ b/lib/Analysis/NaCl/PNaClABIVerifyModule.cpp @@ -17,7 +17,7 @@ #include "llvm/Module.h" #include "llvm/Pass.h" #include "llvm/Support/raw_ostream.h" -#include "llvm/Transforms/NaCl.h" +#include "llvm/Analysis/NaCl.h" using namespace llvm; namespace { @@ -27,6 +27,11 @@ struct PNaClABIVerifyModule : public ModulePass { static char ID; PNaClABIVerifyModule() : ModulePass(ID) {} bool runOnModule(Module &M); + // For now, this print method exists to allow us to run the pass with + // opt -analyze to avoid dumping the result to stdout, to make testing + // simpler. In the future we will probably want to make it do something + // useful. + virtual void print(llvm::raw_ostream &O, const Module *M) const {}; }; static const char* LinkageName(GlobalValue::LinkageTypes LT) { @@ -69,7 +74,7 @@ bool PNaClABIVerifyModule::runOnModule(Module &M) { break; default: errs() << (Twine("Variable ") + MI->getName() + - " has Disallowed linkage type: " + + " has disallowed linkage type: " + LinkageName(MI->getLinkage()) + "\n"); } } @@ -78,7 +83,7 @@ bool PNaClABIVerifyModule::runOnModule(Module &M) { char PNaClABIVerifyModule::ID = 0; -static RegisterPass<PNaClABIVerifyModule> X("pnaclabi-module", +static RegisterPass<PNaClABIVerifyModule> X("verify-pnaclabi-module", "Verify module for PNaCl", false, false); ModulePass *llvm::createPNaClABIVerifyModulePass() { diff --git a/test/NaCl/PNaClABI/instructions.ll b/test/NaCl/PNaClABI/instructions.ll new file mode 100644 index 0000000000..2a8ccbdaca --- /dev/null +++ b/test/NaCl/PNaClABI/instructions.ll @@ -0,0 +1,20 @@ +; RUN: opt -verify-pnaclabi-functions -analyze < %s |& FileCheck %s +; Test instruction opcodes allowed by PNaCl ABI + +target datalayout = "e-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-p:32:32:32-v128:32:32" +target triple = "le32-unknown-nacl" + +define i32 @terminators() nounwind { +; Terminator instructions +terminators: + ret i32 0 + br i1 0, label %next2, label %next +next: + switch i32 1, label %next2 [i32 0, label %next] +next2: + unreachable + resume i8 0 + indirectbr i8* undef, [label %next, label %next2] +; CHECK-NOT: disallowed +; CHECK: Function terminators has disallowed instruction: indirectbr +}
\ No newline at end of file diff --git a/test/NaCl/PNaClABI/linkagetypes.ll b/test/NaCl/PNaClABI/linkagetypes.ll new file mode 100644 index 0000000000..477b7d6d91 --- /dev/null +++ b/test/NaCl/PNaClABI/linkagetypes.ll @@ -0,0 +1,37 @@ +; RUN: opt -verify-pnaclabi-module -analyze < %s |& FileCheck %s +; Test linkage types allowed by PNaCl ABI + +target datalayout = "e-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-p:32:32:32-v128:32:32" +target triple = "le32-unknown-nacl" + + +@gv_external = external global i8 +@gv_private = private global i8 0 +@gv_linker_private = linker_private global i32 0 +; CHECK-NOT: disallowed +; CHECK: gv_linker_private has disallowed linkage type: linker_private +@gv_linker_private_weak = linker_private_weak global i32 0 +; CHECK: gv_linker_private_weak has disallowed linkage type: linker_private_weak +@gv_internal = internal global i8 0 +@gv_linkonce = linkonce global i8 0 +; CHECK-NOT: disallowed +; CHECK: gv_linkonce has disallowed linkage type: linkonce +@gv_linkonce_odr = linkonce_odr global i8 0 +; CHECK: gv_linkonce_odr has disallowed linkage type: linkonce_odr +@gv_linkonce_odr_auto_hide = linkonce_odr_auto_hide global i8 0 +; CHECK: gv_linkonce_odr_auto_hide has disallowed linkage type: linkonce_odr_auto_hide +@gv_weak = weak global i8 0 +; CHECK: gv_weak has disallowed linkage type: weak +@gv_weak_odr = weak_odr global i8 0 +; CHECK: gv_weak_odr has disallowed linkage type: weak_odr +@gv_common = common global i8 0 +; CHECK: gv_common has disallowed linkage type: common +@gv_appending = appending global [1 x i8] zeroinitializer +; CHECK: gv_appending has disallowed linkage type: appending +@gv_dllimport = dllimport global i8 +; CHECK: gv_dllimport has disallowed linkage type: dllimport +@gv_dllexport = dllexport global i8 0 +; CHECK: gv_dllexport has disallowed linkage type: dllexport +@gv_extern_weak = extern_weak global i8 +; CHECK: gv_extern_weak has disallowed linkage type: extern_weak +@gv_avilable_externally = available_externally global i8 0 diff --git a/test/NaCl/PNaClABI/lit.local.cfg b/test/NaCl/PNaClABI/lit.local.cfg new file mode 100644 index 0000000000..c6106e4746 --- /dev/null +++ b/test/NaCl/PNaClABI/lit.local.cfg @@ -0,0 +1 @@ +config.suffixes = ['.ll'] |