From 94908088a831141cfbdd15fc5837dccf30cfeeb6 Mon Sep 17 00:00:00 2001 From: George Burgess IV Date: Thu, 16 Apr 2020 10:56:19 -0700 Subject: [CodeGen] fix inline builtin-related breakage from D78162 In cases where we have multiple decls of an inline builtin, we may need to go hunting for the one with a definition when setting function attributes. An additional test-case was provided on https://github.com/ClangBuiltLinux/linux/issues/979 --- clang/lib/CodeGen/CodeGenModule.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'clang/lib/CodeGen/CodeGenModule.cpp') diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 1243ce50ec8d..ce28d741225e 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -1909,9 +1909,15 @@ void CodeGenModule::SetFunctionAttributes(GlobalDecl GD, llvm::Function *F, F->setSection(SA->getName()); // If we plan on emitting this inline builtin, we can't treat it as a builtin. - if (FD->isInlineBuiltinDeclaration() && shouldEmitFunction(FD)) { - F->addAttribute(llvm::AttributeList::FunctionIndex, - llvm::Attribute::NoBuiltin); + if (FD->isInlineBuiltinDeclaration()) { + const FunctionDecl *FDBody; + bool HasBody = FD->hasBody(FDBody); + (void)HasBody; + assert(HasBody && "Inline builtin declarations should always have an " + "available body!"); + if (shouldEmitFunction(FDBody)) + F->addAttribute(llvm::AttributeList::FunctionIndex, + llvm::Attribute::NoBuiltin); } if (FD->isReplaceableGlobalAllocationFunction()) { -- cgit v1.2.3