llvm.org GIT mirror llvm / 5e4558e
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 Alexey Samsonov 6 years ago
3 changed file(s) with 10 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
1919 /// the well-known calling conventions.
2020 ///
2121 namespace CallingConv {
22 /// LLVM IR allows to use arbitrary numbers as calling convention identifiers.
23 typedef unsigned ID;
24
2225 /// A set of enums which specify the assigned numeric values for known llvm
2326 /// calling conventions.
2427 /// @brief LLVM Calling Convention Representation
25 enum ID {
28 enum {
2629 /// C - The default llvm calling convention, compatible with C. This
2730 /// convention is the only calling convention that supports varargs calls.
2831 /// As with typical C calling conventions, the callee/caller have to
14631463 /// ::= 'preserve_allcc'
14641464 /// ::= 'cc' UINT
14651465 ///
1466 bool LLParser::ParseOptionalCallingConv(CallingConv::ID &CC) {
1466 bool LLParser::ParseOptionalCallingConv(unsigned &CC) {
14671467 switch (Lex.getKind()) {
14681468 default: CC = CallingConv::C; return false;
14691469 case lltok::kw_ccc: CC = CallingConv::C; break;
14881488 case lltok::kw_preserve_mostcc:CC = CallingConv::PreserveMost; break;
14891489 case lltok::kw_preserve_allcc: CC = CallingConv::PreserveAll; break;
14901490 case lltok::kw_cc: {
1491 unsigned ArbitraryCC;
14921491 Lex.Lex();
1493 if (ParseUInt32(ArbitraryCC))
1494 return true;
1495 CC = static_cast(ArbitraryCC);
1496 return false;
1492 return ParseUInt32(CC);
14971493 }
14981494 }
14991495
31303126 unsigned Visibility;
31313127 unsigned DLLStorageClass;
31323128 AttrBuilder RetAttrs;
3133 CallingConv::ID CC;
3129 unsigned CC;
31343130 Type *RetType = nullptr;
31353131 LocTy RetTypeLoc = Lex.getLoc();
31363132 if (ParseOptionalLinkage(Linkage) ||
38023798 AttrBuilder RetAttrs, FnAttrs;
38033799 std::vector FwdRefAttrGrps;
38043800 LocTy NoBuiltinLoc;
3805 CallingConv::ID CC;
3801 unsigned CC;
38063802 Type *RetType = nullptr;
38073803 LocTy RetTypeLoc;
38083804 ValID CalleeID;
42164212 AttrBuilder RetAttrs, FnAttrs;
42174213 std::vector FwdRefAttrGrps;
42184214 LocTy BuiltinLoc;
4219 CallingConv::ID CC;
4215 unsigned CC;
42204216 Type *RetType = nullptr;
42214217 LocTy RetTypeLoc;
42224218 ValID CalleeID;
225225 }
226226 bool ParseOptionalVisibility(unsigned &Visibility);
227227 bool ParseOptionalDLLStorageClass(unsigned &DLLStorageClass);
228 bool ParseOptionalCallingConv(CallingConv::ID &CC);
228 bool ParseOptionalCallingConv(unsigned &CC);
229229 bool ParseOptionalAlignment(unsigned &Alignment);
230230 bool ParseOptionalDereferenceableBytes(uint64_t &Bytes);
231231 bool ParseScopeAndOrdering(bool isAtomic, SynchronizationScope &Scope,