Author: Vitaly Buka Date: 2026-10-23T02:02:24Z New Revision: cd9ac8eb770e57ba2005dabd047b6c4dccc4f7b3
URL: https://github.com/llvm/llvm-project/commit/cd9ac8eb770e57ba2005dabd047b6c4dccc4f7b3 DIFF: https://github.com/llvm/llvm-project/commit/cd9ac8eb770e57ba2005dabd047b6c4dccc4f7b3.diff LOG: [NFC][clang][test] Split inline builtin tests and add strlen test (#234414) Split `memcpy-inline-builtin-no-extern.c` into separate files for `memcpy`, `memcmp`, and `umask`, and use `--filter "call "` to keep the checks concise. Add `strlen-inline-builtin.c` to test `section` on an inline builtin. Assisted-by: Gemini Added: clang/test/CodeGen/memcmp-inline-builtin.c clang/test/CodeGen/strlen-inline-builtin.c clang/test/CodeGen/umask-inline-builtin.c Modified: clang/test/CodeGen/memcpy-inline-builtin-no-extern.c Removed: ################################################################################ diff --git a/clang/test/CodeGen/memcmp-inline-builtin.c b/clang/test/CodeGen/memcmp-inline-builtin.c new file mode 100644 index 0000000000000..c018ce2ccceae --- /dev/null +++ b/clang/test/CodeGen/memcmp-inline-builtin.c @@ -0,0 +1,24 @@ +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --check-attributes --filter "call " --include-generated-funcs --version 6 +// RUN: %clang_cc1 -triple x86_64 -emit-llvm -disable-llvm-passes -o - %s | FileCheck %s + +typedef unsigned long size_t; + +extern inline __attribute__((always_inline)) __attribute__((gnu_inline)) +int memcmp(const void *a, const void *b, size_t c) { + return __builtin_memcmp(a, b, c); +} + +int bar(const void *a, const void *b, size_t c) { + return memcmp(a, b, c); +} +// CHECK: Function Attrs: noinline nounwind optnone +// CHECK-LABEL: define dso_local i32 @bar( +// CHECK-SAME: ptr noundef [[A:%.*]], ptr noundef [[B:%.*]], i64 noundef [[C:%.*]]) #[[ATTR0:[0-9]+]] { +// CHECK: [[CALL:%.*]] = call i32 @memcmp.inline(ptr noundef [[TMP0:%.*]], ptr noundef [[TMP1:%.*]], i64 noundef [[TMP2:%.*]]) +// +// +// CHECK: Function Attrs: alwaysinline nounwind +// CHECK-LABEL: define internal i32 @memcmp.inline( +// CHECK-SAME: ptr [[A:%.*]], ptr [[B:%.*]], i64 [[C:%.*]]) #[[ATTR2:[0-9]+]] { +// CHECK: [[CALL:%.*]] = call i32 @memcmp(ptr noundef [[TMP0:%.*]], ptr noundef [[TMP1:%.*]], i64 noundef [[TMP2:%.*]]) #[[ATTR3:[0-9]+]] +// diff --git a/clang/test/CodeGen/memcpy-inline-builtin-no-extern.c b/clang/test/CodeGen/memcpy-inline-builtin-no-extern.c index a373346f5fcee..4cb0b5f06309c 100644 --- a/clang/test/CodeGen/memcpy-inline-builtin-no-extern.c +++ b/clang/test/CodeGen/memcpy-inline-builtin-no-extern.c @@ -1,123 +1,25 @@ -// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --check-attributes --include-generated-funcs --version 6 +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --check-attributes --filter "call " --include-generated-funcs --version 6 // RUN: %clang_cc1 -triple x86_64 -emit-llvm -disable-llvm-passes -o - %s | FileCheck %s -// Verifies that clang-generated *.inline are flagged as internal. typedef unsigned long size_t; -#define AVAILABLE_EXTERNALLY extern inline __attribute__((always_inline)) __attribute__((gnu_inline)) -// Clang recognizes an inline builtin and renames it to memcmp.inline to prevent conflict with builtins. -AVAILABLE_EXTERNALLY int memcmp(const void *a, const void *b, size_t c) { - return __builtin_memcmp(a, b, c); -} - -int bar(const void *a, const void *b, size_t c) { - return memcmp(a, b, c); -} - // Note that extern has been omitted here. -#define TRIPLE_INLINE inline __attribute__((always_inline)) __attribute__((gnu_inline)) - -// Clang recognizes an inline builtin and renames it to memcpy.inline to prevent conflict with builtins. -TRIPLE_INLINE void *memcpy(void *a, const void *b, size_t c) { +inline __attribute__((always_inline)) __attribute__((gnu_inline)) +void *memcpy(void *a, const void *b, size_t c) { return __builtin_memcpy(a, b, c); } void *foo(void *a, const void *b, size_t c) { return memcpy(a, b, c); } - -AVAILABLE_EXTERNALLY __attribute__((preserve_most)) int umask(int m) { - return m; -} - -int call_umask(int m) { - return umask(m); -} -// CHECK: Function Attrs: noinline nounwind optnone -// CHECK-LABEL: define dso_local i32 @bar( -// CHECK-SAME: ptr noundef [[A:%.*]], ptr noundef [[B:%.*]], i64 noundef [[C:%.*]]) #[[ATTR0:[0-9]+]] { -// CHECK-NEXT: [[ENTRY:.*:]] -// CHECK-NEXT: [[A_ADDR:%.*]] = alloca ptr, align 8 -// CHECK-NEXT: [[B_ADDR:%.*]] = alloca ptr, align 8 -// CHECK-NEXT: [[C_ADDR:%.*]] = alloca i64, align 8 -// CHECK-NEXT: store ptr [[A]], ptr [[A_ADDR]], align 8 -// CHECK-NEXT: store ptr [[B]], ptr [[B_ADDR]], align 8 -// CHECK-NEXT: store i64 [[C]], ptr [[C_ADDR]], align 8 -// CHECK-NEXT: [[TMP0:%.*]] = load ptr, ptr [[A_ADDR]], align 8 -// CHECK-NEXT: [[TMP1:%.*]] = load ptr, ptr [[B_ADDR]], align 8 -// CHECK-NEXT: [[TMP2:%.*]] = load i64, ptr [[C_ADDR]], align 8 -// CHECK-NEXT: [[CALL:%.*]] = call i32 @memcmp.inline(ptr noundef [[TMP0]], ptr noundef [[TMP1]], i64 noundef [[TMP2]]) -// CHECK-NEXT: ret i32 [[CALL]] -// -// -// CHECK: Function Attrs: alwaysinline nounwind -// CHECK-LABEL: define internal i32 @memcmp.inline( -// CHECK-SAME: ptr [[A:%.*]], ptr [[B:%.*]], i64 [[C:%.*]]) #[[ATTR2:[0-9]+]] { -// CHECK-NEXT: [[ENTRY:.*:]] -// CHECK-NEXT: [[A_ADDR:%.*]] = alloca ptr, align 8 -// CHECK-NEXT: [[B_ADDR:%.*]] = alloca ptr, align 8 -// CHECK-NEXT: [[C_ADDR:%.*]] = alloca i64, align 8 -// CHECK-NEXT: store ptr [[A]], ptr [[A_ADDR]], align 8 -// CHECK-NEXT: store ptr [[B]], ptr [[B_ADDR]], align 8 -// CHECK-NEXT: store i64 [[C]], ptr [[C_ADDR]], align 8 -// CHECK-NEXT: [[TMP0:%.*]] = load ptr, ptr [[A_ADDR]], align 8 -// CHECK-NEXT: [[TMP1:%.*]] = load ptr, ptr [[B_ADDR]], align 8 -// CHECK-NEXT: [[TMP2:%.*]] = load i64, ptr [[C_ADDR]], align 8 -// CHECK-NEXT: [[CALL:%.*]] = call i32 @memcmp(ptr noundef [[TMP0]], ptr noundef [[TMP1]], i64 noundef [[TMP2]]) #[[ATTR4:[0-9]+]] -// CHECK-NEXT: ret i32 [[CALL]] -// -// // CHECK: Function Attrs: alwaysinline nounwind // CHECK-LABEL: define internal ptr @memcpy.inline( -// CHECK-SAME: ptr [[A:%.*]], ptr [[B:%.*]], i64 [[C:%.*]]) #[[ATTR2]] { -// CHECK-NEXT: [[ENTRY:.*:]] -// CHECK-NEXT: [[A_ADDR:%.*]] = alloca ptr, align 8 -// CHECK-NEXT: [[B_ADDR:%.*]] = alloca ptr, align 8 -// CHECK-NEXT: [[C_ADDR:%.*]] = alloca i64, align 8 -// CHECK-NEXT: store ptr [[A]], ptr [[A_ADDR]], align 8 -// CHECK-NEXT: store ptr [[B]], ptr [[B_ADDR]], align 8 -// CHECK-NEXT: store i64 [[C]], ptr [[C_ADDR]], align 8 -// CHECK-NEXT: [[TMP0:%.*]] = load ptr, ptr [[A_ADDR]], align 8 -// CHECK-NEXT: [[TMP1:%.*]] = load ptr, ptr [[B_ADDR]], align 8 -// CHECK-NEXT: [[TMP2:%.*]] = load i64, ptr [[C_ADDR]], align 8 -// CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr align 1 [[TMP0]], ptr align 1 [[TMP1]], i64 [[TMP2]], i1 false) -// CHECK-NEXT: ret ptr [[TMP0]] +// CHECK-SAME: ptr [[A:%.*]], ptr [[B:%.*]], i64 [[C:%.*]]) #[[ATTR1:[0-9]+]] { +// CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align 1 [[TMP0:%.*]], ptr align 1 [[TMP1:%.*]], i64 [[TMP2:%.*]], i1 false) // // // CHECK: Function Attrs: noinline nounwind optnone // CHECK-LABEL: define dso_local ptr @foo( -// CHECK-SAME: ptr noundef [[A:%.*]], ptr noundef [[B:%.*]], i64 noundef [[C:%.*]]) #[[ATTR0]] { -// CHECK-NEXT: [[ENTRY:.*:]] -// CHECK-NEXT: [[A_ADDR:%.*]] = alloca ptr, align 8 -// CHECK-NEXT: [[B_ADDR:%.*]] = alloca ptr, align 8 -// CHECK-NEXT: [[C_ADDR:%.*]] = alloca i64, align 8 -// CHECK-NEXT: store ptr [[A]], ptr [[A_ADDR]], align 8 -// CHECK-NEXT: store ptr [[B]], ptr [[B_ADDR]], align 8 -// CHECK-NEXT: store i64 [[C]], ptr [[C_ADDR]], align 8 -// CHECK-NEXT: [[TMP0:%.*]] = load ptr, ptr [[A_ADDR]], align 8 -// CHECK-NEXT: [[TMP1:%.*]] = load ptr, ptr [[B_ADDR]], align 8 -// CHECK-NEXT: [[TMP2:%.*]] = load i64, ptr [[C_ADDR]], align 8 -// CHECK-NEXT: [[CALL:%.*]] = call ptr @memcpy.inline(ptr noundef [[TMP0]], ptr noundef [[TMP1]], i64 noundef [[TMP2]]) #[[ATTR4]] -// CHECK-NEXT: ret ptr [[CALL]] -// -// -// CHECK: Function Attrs: noinline nounwind optnone -// CHECK-LABEL: define dso_local i32 @call_umask( -// CHECK-SAME: i32 noundef [[M:%.*]]) #[[ATTR0]] { -// CHECK-NEXT: [[ENTRY:.*:]] -// CHECK-NEXT: [[M_ADDR:%.*]] = alloca i32, align 4 -// CHECK-NEXT: store i32 [[M]], ptr [[M_ADDR]], align 4 -// CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[M_ADDR]], align 4 -// CHECK-NEXT: [[CALL:%.*]] = call preserve_mostcc i32 @umask.inline(i32 noundef [[TMP0]]) #[[ATTR4]] -// CHECK-NEXT: ret i32 [[CALL]] -// -// -// CHECK: Function Attrs: alwaysinline nounwind -// CHECK-LABEL: define internal i32 @umask.inline( -// CHECK-SAME: i32 [[M:%.*]]) #[[ATTR2]] { -// CHECK-NEXT: [[ENTRY:.*:]] -// CHECK-NEXT: [[M_ADDR:%.*]] = alloca i32, align 4 -// CHECK-NEXT: store i32 [[M]], ptr [[M_ADDR]], align 4 -// CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[M_ADDR]], align 4 -// CHECK-NEXT: ret i32 [[TMP0]] +// CHECK-SAME: ptr noundef [[A:%.*]], ptr noundef [[B:%.*]], i64 noundef [[C:%.*]]) #[[ATTR3:[0-9]+]] { +// CHECK: [[CALL:%.*]] = call ptr @memcpy.inline(ptr noundef [[TMP0:%.*]], ptr noundef [[TMP1:%.*]], i64 noundef [[TMP2:%.*]]) #[[ATTR4:[0-9]+]] // diff --git a/clang/test/CodeGen/strlen-inline-builtin.c b/clang/test/CodeGen/strlen-inline-builtin.c new file mode 100644 index 0000000000000..f24f5adb6b490 --- /dev/null +++ b/clang/test/CodeGen/strlen-inline-builtin.c @@ -0,0 +1,25 @@ +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --check-attributes --filter "call " --include-generated-funcs --version 6 +// RUN: %clang_cc1 -triple x86_64 -emit-llvm -disable-llvm-passes -o - %s | FileCheck %s + +typedef unsigned long size_t; + +size_t strlen(const char *s); +void *strlen_ptr = strlen; + +extern inline __attribute__((always_inline)) __attribute__((gnu_inline)) +__attribute__((section("my_sec"))) size_t strlen(const char *s) { + return 0; +} + +size_t call_strlen(const char *s) { + return strlen(s); +} +// CHECK: Function Attrs: noinline nounwind optnone +// CHECK-LABEL: define dso_local i64 @call_strlen( +// CHECK-SAME: ptr noundef [[S:%.*]]) #[[ATTR1:[0-9]+]] { +// CHECK: [[CALL:%.*]] = call i64 @strlen.inline(ptr noundef [[TMP0:%.*]]) #[[ATTR3:[0-9]+]] +// +// +// CHECK: Function Attrs: alwaysinline nounwind +// CHECK-LABEL: define internal i64 @strlen.inline( +// CHECK-SAME: ptr [[S:%.*]]) #[[ATTR2:[0-9]+]] { diff --git a/clang/test/CodeGen/umask-inline-builtin.c b/clang/test/CodeGen/umask-inline-builtin.c new file mode 100644 index 0000000000000..1b66b9dff1bdb --- /dev/null +++ b/clang/test/CodeGen/umask-inline-builtin.c @@ -0,0 +1,20 @@ +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --check-attributes --filter "call " --include-generated-funcs --version 6 +// RUN: %clang_cc1 -triple x86_64 -emit-llvm -disable-llvm-passes -o - %s | FileCheck %s + +extern inline __attribute__((always_inline)) __attribute__((gnu_inline)) +__attribute__((preserve_most)) int umask(int m) { + return m; +} + +int call_umask(int m) { + return umask(m); +} +// CHECK: Function Attrs: noinline nounwind optnone +// CHECK-LABEL: define dso_local i32 @call_umask( +// CHECK-SAME: i32 noundef [[M:%.*]]) #[[ATTR0:[0-9]+]] { +// CHECK: [[CALL:%.*]] = call preserve_mostcc i32 @umask.inline(i32 noundef [[TMP0:%.*]]) #[[ATTR3:[0-9]+]] +// +// +// CHECK: Function Attrs: alwaysinline nounwind +// CHECK-LABEL: define internal i32 @umask.inline( +// CHECK-SAME: i32 [[M:%.*]]) #[[ATTR2:[0-9]+]] { _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
