Make CallingConv::ID an alias of "unsigned".

Summary:
Make CallingConv::ID a plain unsigned instead of enum with a
fixed set of valus. LLVM IR allows arbitraty calling conventions (you are
free to write cc12345), and loading them as enum is an undefined
behavior. This was reported by UBSan.

Test Plan: llvm regression test suite

Reviewers: nicholas

Reviewed By: nicholas

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D5248

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@217529 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Alexey Samsonov 2014-09-10 18:00:17 +00:00
parent 87c977a52b
commit 5e4558e5a8
3 changed files with 10 additions and 11 deletions

View File

@ -20,10 +20,13 @@ namespace llvm {
/// the well-known calling conventions. /// the well-known calling conventions.
/// ///
namespace CallingConv { namespace CallingConv {
/// LLVM IR allows to use arbitrary numbers as calling convention identifiers.
typedef unsigned ID;
/// A set of enums which specify the assigned numeric values for known llvm /// A set of enums which specify the assigned numeric values for known llvm
/// calling conventions. /// calling conventions.
/// @brief LLVM Calling Convention Representation /// @brief LLVM Calling Convention Representation
enum ID { enum {
/// C - The default llvm calling convention, compatible with C. This /// C - The default llvm calling convention, compatible with C. This
/// convention is the only calling convention that supports varargs calls. /// convention is the only calling convention that supports varargs calls.
/// As with typical C calling conventions, the callee/caller have to /// As with typical C calling conventions, the callee/caller have to

View File

@ -1464,7 +1464,7 @@ bool LLParser::ParseOptionalDLLStorageClass(unsigned &Res) {
/// ::= 'preserve_allcc' /// ::= 'preserve_allcc'
/// ::= 'cc' UINT /// ::= 'cc' UINT
/// ///
bool LLParser::ParseOptionalCallingConv(CallingConv::ID &CC) { bool LLParser::ParseOptionalCallingConv(unsigned &CC) {
switch (Lex.getKind()) { switch (Lex.getKind()) {
default: CC = CallingConv::C; return false; default: CC = CallingConv::C; return false;
case lltok::kw_ccc: CC = CallingConv::C; break; case lltok::kw_ccc: CC = CallingConv::C; break;
@ -1489,12 +1489,8 @@ bool LLParser::ParseOptionalCallingConv(CallingConv::ID &CC) {
case lltok::kw_preserve_mostcc:CC = CallingConv::PreserveMost; break; case lltok::kw_preserve_mostcc:CC = CallingConv::PreserveMost; break;
case lltok::kw_preserve_allcc: CC = CallingConv::PreserveAll; break; case lltok::kw_preserve_allcc: CC = CallingConv::PreserveAll; break;
case lltok::kw_cc: { case lltok::kw_cc: {
unsigned ArbitraryCC;
Lex.Lex(); Lex.Lex();
if (ParseUInt32(ArbitraryCC)) return ParseUInt32(CC);
return true;
CC = static_cast<CallingConv::ID>(ArbitraryCC);
return false;
} }
} }
@ -3131,7 +3127,7 @@ bool LLParser::ParseFunctionHeader(Function *&Fn, bool isDefine) {
unsigned Visibility; unsigned Visibility;
unsigned DLLStorageClass; unsigned DLLStorageClass;
AttrBuilder RetAttrs; AttrBuilder RetAttrs;
CallingConv::ID CC; unsigned CC;
Type *RetType = nullptr; Type *RetType = nullptr;
LocTy RetTypeLoc = Lex.getLoc(); LocTy RetTypeLoc = Lex.getLoc();
if (ParseOptionalLinkage(Linkage) || if (ParseOptionalLinkage(Linkage) ||
@ -3803,7 +3799,7 @@ bool LLParser::ParseInvoke(Instruction *&Inst, PerFunctionState &PFS) {
AttrBuilder RetAttrs, FnAttrs; AttrBuilder RetAttrs, FnAttrs;
std::vector<unsigned> FwdRefAttrGrps; std::vector<unsigned> FwdRefAttrGrps;
LocTy NoBuiltinLoc; LocTy NoBuiltinLoc;
CallingConv::ID CC; unsigned CC;
Type *RetType = nullptr; Type *RetType = nullptr;
LocTy RetTypeLoc; LocTy RetTypeLoc;
ValID CalleeID; ValID CalleeID;
@ -4217,7 +4213,7 @@ bool LLParser::ParseCall(Instruction *&Inst, PerFunctionState &PFS,
AttrBuilder RetAttrs, FnAttrs; AttrBuilder RetAttrs, FnAttrs;
std::vector<unsigned> FwdRefAttrGrps; std::vector<unsigned> FwdRefAttrGrps;
LocTy BuiltinLoc; LocTy BuiltinLoc;
CallingConv::ID CC; unsigned CC;
Type *RetType = nullptr; Type *RetType = nullptr;
LocTy RetTypeLoc; LocTy RetTypeLoc;
ValID CalleeID; ValID CalleeID;

View File

@ -226,7 +226,7 @@ namespace llvm {
} }
bool ParseOptionalVisibility(unsigned &Visibility); bool ParseOptionalVisibility(unsigned &Visibility);
bool ParseOptionalDLLStorageClass(unsigned &DLLStorageClass); bool ParseOptionalDLLStorageClass(unsigned &DLLStorageClass);
bool ParseOptionalCallingConv(CallingConv::ID &CC); bool ParseOptionalCallingConv(unsigned &CC);
bool ParseOptionalAlignment(unsigned &Alignment); bool ParseOptionalAlignment(unsigned &Alignment);
bool ParseOptionalDereferenceableBytes(uint64_t &Bytes); bool ParseOptionalDereferenceableBytes(uint64_t &Bytes);
bool ParseScopeAndOrdering(bool isAtomic, SynchronizationScope &Scope, bool ParseScopeAndOrdering(bool isAtomic, SynchronizationScope &Scope,