[clang] 1676b1f - [clang] Use the appropriate definition when checking FunctionDecl::isInlineBuiltinDeclaration
via cfe-commits
cfe-commits at lists.llvm.org
Wed May 31 12:13:22 PDT 2023
Author: serge-sans-paille
Date: 2023-05-31T21:13:07+02:00
New Revision: 1676b1ff63afb1cadc523d74f1e8f2c75fd49126
URL: https://github.com/llvm/llvm-project/commit/1676b1ff63afb1cadc523d74f1e8f2c75fd49126
DIFF: https://github.com/llvm/llvm-project/commit/1676b1ff63afb1cadc523d74f1e8f2c75fd49126.diff
LOG: [clang] Use the appropriate definition when checking FunctionDecl::isInlineBuiltinDeclaration
This is a follow-up to https://reviews.llvm.org/D148723 and fixes the
bug reported by @mstorsjo.
Differential Revision: https://reviews.llvm.org/D151783
Added:
clang/test/CodeGen/memcpy-inline-builtin-mutliple-decl.c
Modified:
clang/lib/AST/Decl.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 99926b2786ef..85d8f11aafde 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -3322,7 +3322,7 @@ bool FunctionDecl::isInlineBuiltinDeclaration() const {
return false;
ASTContext &Context = getASTContext();
- switch (Context.GetGVALinkageForFunction(this)) {
+ switch (Context.GetGVALinkageForFunction(Definition)) {
case GVA_Internal:
case GVA_DiscardableODR:
case GVA_StrongODR:
diff --git a/clang/test/CodeGen/memcpy-inline-builtin-mutliple-decl.c b/clang/test/CodeGen/memcpy-inline-builtin-mutliple-decl.c
new file mode 100644
index 000000000000..39a964c51c7d
--- /dev/null
+++ b/clang/test/CodeGen/memcpy-inline-builtin-mutliple-decl.c
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -triple i686-w64-mingw32 -S -emit-llvm -disable-llvm-passes -o - %s | FileCheck %s
+//
+// Verifies that clang detects memcpy inline version and uses it instead of the builtin.
+// Checks that clang correctly walks through multiple forward declaration.
+
+typedef unsigned int size_t;
+
+void *memcpy(void *_Dst, const void *_Src, size_t _Size);
+
+extern __inline__ __attribute__((__always_inline__, __gnu_inline__)) __attribute__((__artificial__))
+void *memcpy(void *__dst, const void *__src, size_t __n)
+{
+ return __builtin___memcpy_chk(__dst, __src, __n, __builtin_object_size((__dst), ((0) > 0) && (2 > 1)));
+}
+
+void *memcpy(void *_Dst, const void *_Src, size_t _Size);
+
+char *a, *b;
+void func(void) {
+ memcpy(a, b, 42);
+}
+
+// CHECK-LABEL: define {{.*}} @func(
+// CHECK: call ptr @memcpy.inline
+
+// CHECK-LABEL: declare {{.*}} @memcpy(
+
+// CHECK-LABEL: define {{.*}} @memcpy.inline(
+// CHECK: call ptr @__memcpy_chk
More information about the cfe-commits
mailing list