From cdfa631f06e1e49e55bfe9e3109cafe544ef1664 Mon Sep 17 00:00:00 2001 From: Alexey Samsonov Date: Thu, 28 Aug 2014 23:34:32 +0000 Subject: [PATCH] Don't load invalid enum value in Sema::LazilyCreateBuiltin. This bug was reported by UBSan. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@216696 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaDecl.cpp | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index e02fa26837..9f49e68c07 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -1623,32 +1623,30 @@ static StringRef getHeaderName(ASTContext::GetBuiltinTypeError Error) { /// file scope. lazily create a decl for it. ForRedeclaration is true /// if we're creating this built-in in anticipation of redeclaring the /// built-in. -NamedDecl *Sema::LazilyCreateBuiltin(IdentifierInfo *II, unsigned bid, +NamedDecl *Sema::LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID, Scope *S, bool ForRedeclaration, SourceLocation Loc) { LookupPredefedObjCSuperType(*this, S, II); - - Builtin::ID BID = (Builtin::ID)bid; ASTContext::GetBuiltinTypeError Error; - QualType R = Context.GetBuiltinType(BID, Error); + QualType R = Context.GetBuiltinType(ID, Error); if (Error) { if (ForRedeclaration) Diag(Loc, diag::warn_implicit_decl_requires_sysheader) << getHeaderName(Error) - << Context.BuiltinInfo.GetName(BID); + << Context.BuiltinInfo.GetName(ID); return nullptr; } - if (!ForRedeclaration && Context.BuiltinInfo.isPredefinedLibFunction(BID)) { + if (!ForRedeclaration && Context.BuiltinInfo.isPredefinedLibFunction(ID)) { Diag(Loc, diag::ext_implicit_lib_function_decl) - << Context.BuiltinInfo.GetName(BID) + << Context.BuiltinInfo.GetName(ID) << R; - if (Context.BuiltinInfo.getHeaderName(BID) && + if (Context.BuiltinInfo.getHeaderName(ID) && !Diags.isIgnored(diag::ext_implicit_lib_function_decl, Loc)) Diag(Loc, diag::note_include_header_or_declare) - << Context.BuiltinInfo.getHeaderName(BID) - << Context.BuiltinInfo.GetName(BID); + << Context.BuiltinInfo.getHeaderName(ID) + << Context.BuiltinInfo.GetName(ID); } DeclContext *Parent = Context.getTranslationUnitDecl(); -- 2.40.0