[llvm-branch-commits] [clang] [clang][CodeGen] Copy function attributes to .inline builtin clones (PR #234081)

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Oct 20 23:24:52 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-codegen

Author: Vitaly Buka (vitalybuka)

<details>
<summary>Changes</summary>

0f0e31cf511d created a separate `.inline` function for inline builtins instead
of renaming `Fn` in place, but only set `alwaysinline` on the clone.

Exposed by #<!-- -->215264: missing target attributes can prevent inlining `.inline`
clones, and missing `noundef` parameter attributes cause MSan false positives
when the clone is not inlined.

Assisted-by: Gemini


---
Full diff: https://github.com/llvm/llvm-project/pull/234081.diff


2 Files Affected:

- (modified) clang/lib/CodeGen/CodeGenFunction.cpp (+4-3) 
- (modified) clang/test/CodeGen/memcpy-inline-builtin-no-extern.c (+6-6) 


``````````diff
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp
index e5bca359e6a85..73bdfa94d4911 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -1501,12 +1501,13 @@ void CodeGenFunction::GenerateCode(GlobalDecl GD, llvm::Function *Fn,
     std::string FDInlineName = (Fn->getName() + ".inline").str();
     llvm::Module *M = Fn->getParent();
     llvm::Function *Clone = M->getFunction(FDInlineName);
-    if (!Clone) {
+    if (!Clone)
       Clone = llvm::Function::Create(Fn->getFunctionType(),
                                      llvm::GlobalValue::InternalLinkage,
                                      Fn->getAddressSpace(), FDInlineName, M);
-      Clone->addFnAttr(llvm::Attribute::AlwaysInline);
-    }
+    Clone->setAttributes(Fn->getAttributes());
+    CGM.SetLLVMFunctionAttributesForDefinition(FD, Clone);
+    Clone->addFnAttr(llvm::Attribute::AlwaysInline);
     Fn->setLinkage(llvm::GlobalValue::ExternalLinkage);
     Fn = Clone;
   } else {
diff --git a/clang/test/CodeGen/memcpy-inline-builtin-no-extern.c b/clang/test/CodeGen/memcpy-inline-builtin-no-extern.c
index a373346f5fcee..44501c47b5c02 100644
--- a/clang/test/CodeGen/memcpy-inline-builtin-no-extern.c
+++ b/clang/test/CodeGen/memcpy-inline-builtin-no-extern.c
@@ -50,9 +50,9 @@ int call_umask(int m) {
 // CHECK-NEXT:    ret i32 [[CALL]]
 //
 //
-// CHECK: Function Attrs: alwaysinline nounwind
+// CHECK: Function Attrs: alwaysinline nobuiltin nounwind
 // CHECK-LABEL: define internal i32 @memcmp.inline(
-// CHECK-SAME: ptr [[A:%.*]], ptr [[B:%.*]], i64 [[C:%.*]]) #[[ATTR2:[0-9]+]] {
+// CHECK-SAME: ptr noundef [[A:%.*]], ptr noundef [[B:%.*]], i64 noundef [[C:%.*]]) #[[ATTR2:[0-9]+]] {
 // CHECK-NEXT:  [[ENTRY:.*:]]
 // CHECK-NEXT:    [[A_ADDR:%.*]] = alloca ptr, align 8
 // CHECK-NEXT:    [[B_ADDR:%.*]] = alloca ptr, align 8
@@ -67,9 +67,9 @@ int call_umask(int m) {
 // CHECK-NEXT:    ret i32 [[CALL]]
 //
 //
-// CHECK: Function Attrs: alwaysinline nounwind
+// CHECK: Function Attrs: alwaysinline nobuiltin nounwind
 // CHECK-LABEL: define internal ptr @memcpy.inline(
-// CHECK-SAME: ptr [[A:%.*]], ptr [[B:%.*]], i64 [[C:%.*]]) #[[ATTR2]] {
+// CHECK-SAME: ptr noundef [[A:%.*]], ptr noundef [[B:%.*]], i64 noundef [[C:%.*]]) #[[ATTR2]] {
 // CHECK-NEXT:  [[ENTRY:.*:]]
 // CHECK-NEXT:    [[A_ADDR:%.*]] = alloca ptr, align 8
 // CHECK-NEXT:    [[B_ADDR:%.*]] = alloca ptr, align 8
@@ -112,9 +112,9 @@ int call_umask(int m) {
 // CHECK-NEXT:    ret i32 [[CALL]]
 //
 //
-// CHECK: Function Attrs: alwaysinline nounwind
+// CHECK: Function Attrs: alwaysinline nobuiltin nounwind
 // CHECK-LABEL: define internal i32 @umask.inline(
-// CHECK-SAME: i32 [[M:%.*]]) #[[ATTR2]] {
+// CHECK-SAME: i32 noundef [[M:%.*]]) #[[ATTR2]] {
 // CHECK-NEXT:  [[ENTRY:.*:]]
 // CHECK-NEXT:    [[M_ADDR:%.*]] = alloca i32, align 4
 // CHECK-NEXT:    store i32 [[M]], ptr [[M_ADDR]], align 4

``````````

</details>


https://github.com/llvm/llvm-project/pull/234081


More information about the llvm-branch-commits mailing list