[llvm-branch-commits] [clang] eaae6df - [CodeGen] fix inline builtin-related breakage from D78162
Tom Stellard via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu May 7 13:48:59 PDT 2020
Author: George Burgess IV
Date: 2020-05-07T13:47:01-07:00
New Revision: eaae6dfc545000e335e6f89abb9c78818383d7ad
URL: https://github.com/llvm/llvm-project/commit/eaae6dfc545000e335e6f89abb9c78818383d7ad
DIFF: https://github.com/llvm/llvm-project/commit/eaae6dfc545000e335e6f89abb9c78818383d7ad.diff
LOG: [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
(cherry picked from commit 94908088a831141cfbdd15fc5837dccf30cfeeb6)
Added:
clang/test/CodeGen/memcpy-no-nobuiltin-if-not-emitted.cpp
Modified:
clang/lib/CodeGen/CodeGenModule.cpp
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index 73c41dc4cf3f..a735bdd814ed 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1848,9 +1848,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()) {
diff --git a/clang/test/CodeGen/memcpy-no-nobuiltin-if-not-emitted.cpp b/clang/test/CodeGen/memcpy-no-nobuiltin-if-not-emitted.cpp
new file mode 100644
index 000000000000..d27aa9c53413
--- /dev/null
+++ b/clang/test/CodeGen/memcpy-no-nobuiltin-if-not-emitted.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -triple i686-linux-gnu -std=c++11 -S -emit-llvm -o - %s | FileCheck %s
+//
+// Regression test for the issue reported at
+// https://reviews.llvm.org/D78162#1986104
+
+typedef unsigned long size_t;
+
+extern "C" __inline__ __attribute__((__gnu_inline__)) void *memcpy(void *a, const void *b, unsigned c) {
+ return __builtin_memcpy(a, b, c);
+}
+void *memcpy(void *, const void *, unsigned);
+
+// CHECK-LABEL: define void @_Z1av
+void a() { (void)memcpy; }
+
+// CHECK-NOT: nobuiltin
More information about the llvm-branch-commits
mailing list