diff options
author | Mark Seaborn <mseaborn@chromium.org> | 2013-06-06 10:33:01 -0700 |
---|---|---|
committer | Mark Seaborn <mseaborn@chromium.org> | 2013-06-06 10:33:01 -0700 |
commit | bcbad3ce541bc70ab3383d3d77198ceb9e813b46 (patch) | |
tree | 0e259872032346feb3f4e5f2402588602a179d3d /lib | |
parent | 37bdd9174a1cba17b369c8c1f561e70c458e0c13 (diff) |
PNaCl ABI: Strip out calling conventions from functions and calls
Always use the standard C calling conventions. Disallow "fastcc" etc.
BUG=https://code.google.com/p/nativeclient/issues/detail?id=2346
TEST=*.ll tests + PNaCl toolchain trybots
Review URL: https://codereview.chromium.org/16529004
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Analysis/NaCl/PNaClABIVerifyFunctions.cpp | 10 | ||||
-rw-r--r-- | lib/Analysis/NaCl/PNaClABIVerifyModule.cpp | 6 | ||||
-rw-r--r-- | lib/Transforms/NaCl/StripAttributes.cpp | 10 |
3 files changed, 20 insertions, 6 deletions
diff --git a/lib/Analysis/NaCl/PNaClABIVerifyFunctions.cpp b/lib/Analysis/NaCl/PNaClABIVerifyFunctions.cpp index 167cad15d0..a59f6f6682 100644 --- a/lib/Analysis/NaCl/PNaClABIVerifyFunctions.cpp +++ b/lib/Analysis/NaCl/PNaClABIVerifyFunctions.cpp @@ -255,11 +255,14 @@ const char *PNaClABIVerifyFunctions::checkInstruction(const Instruction *Inst) { break; } - case Instruction::Call: - if (cast<CallInst>(Inst)->isInlineAsm()) + case Instruction::Call: { + const CallInst *Call = cast<CallInst>(Inst); + if (Call->isInlineAsm()) return "inline assembly"; - if (!cast<CallInst>(Inst)->getAttributes().isEmpty()) + if (!Call->getAttributes().isEmpty()) return "bad call attributes"; + if (Call->getCallingConv() != CallingConv::C) + return "bad calling convention"; // Intrinsic calls can have multiple pointer arguments and // metadata arguments, so handle them specially. @@ -281,6 +284,7 @@ const char *PNaClABIVerifyFunctions::checkInstruction(const Instruction *Inst) { if (!isNormalizedPtr(Inst->getOperand(PtrOperandIndex))) return "bad function callee operand"; break; + } case Instruction::Switch: { // SwitchInst represents switch cases using array and vector diff --git a/lib/Analysis/NaCl/PNaClABIVerifyModule.cpp b/lib/Analysis/NaCl/PNaClABIVerifyModule.cpp index 91f71c949c..477bc50ec9 100644 --- a/lib/Analysis/NaCl/PNaClABIVerifyModule.cpp +++ b/lib/Analysis/NaCl/PNaClABIVerifyModule.cpp @@ -383,6 +383,12 @@ bool PNaClABIVerifyModule::runOnModule(Module &M) { << "Function " << MI->getName() << " has disallowed attributes:" << getAttributesAsString(MI->getAttributes()) << "\n"; } + if (MI->getCallingConv() != CallingConv::C) { + Reporter->addError() + << "Function " << MI->getName() + << " has disallowed calling convention: " + << MI->getCallingConv() << "\n"; + } } checkGlobalValueCommon(MI); diff --git a/lib/Transforms/NaCl/StripAttributes.cpp b/lib/Transforms/NaCl/StripAttributes.cpp index f5ec0423b4..476c500756 100644 --- a/lib/Transforms/NaCl/StripAttributes.cpp +++ b/lib/Transforms/NaCl/StripAttributes.cpp @@ -8,12 +8,14 @@ //===----------------------------------------------------------------------===// // // This pass strips out attributes that are not supported by PNaCl's -// stable ABI. Currently, this strips out attributes from functions -// and function calls. +// stable ABI. Currently, this strips out: +// +// * Function and argument attributes from functions and function +// calls. +// * Calling conventions from functions and function calls. // // TODO(mseaborn): Strip out the following too: // -// * Calling conventions from functions and function calls. // * "nuw" and "nsw" arithmetic attributes. // * "align" attributes from integer memory accesses. // @@ -131,6 +133,7 @@ static void CheckAttributes(AttributeSet Attrs) { bool StripAttributes::runOnFunction(Function &Func) { CheckAttributes(Func.getAttributes()); Func.setAttributes(AttributeSet()); + Func.setCallingConv(CallingConv::C); for (Function::iterator BB = Func.begin(), E = Func.end(); BB != E; ++BB) { @@ -140,6 +143,7 @@ bool StripAttributes::runOnFunction(Function &Func) { if (Call) { CheckAttributes(Call.getAttributes()); Call.setAttributes(AttributeSet()); + Call.setCallingConv(CallingConv::C); } } } |