Debian Codegraph @

clang/test/CodeGen/attr-modular-format.c

raw
1 // RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck %s
2
3 int printf(const char *fmt, ...) __attribute__((modular_format(__modular_printf, "__printf", "float")));
4 int myprintf(const char *fmt, ...) __attribute__((modular_format(__modular_printf, "__printf", "float"), format(printf, 1, 2)));
5
6 // CHECK-LABEL: define dso_local void @test_inferred_format(
7 // CHECK: {{.*}} = call i32 (ptr, ...) @printf(ptr noundef @.str) #[[ATTR:[0-9]+]]
8 void test_inferred_format(void) {
9 printf("hello");
10 }
11
12 // CHECK-LABEL: define dso_local void @test_explicit_format(
13 // CHECK: {{.*}} = call i32 (ptr, ...) @myprintf(ptr noundef @.str) #[[ATTR:[0-9]+]]
14 void test_explicit_format(void) {
15 myprintf("hello");
16 }
17
18 int redecl(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
19 int redecl(const char *fmt, ...) __attribute__((modular_format(__dupe_impl, "__dupe", "1")));
20 int redecl(const char *fmt, ...) __attribute__((modular_format(__dupe_impl, "__dupe", "1")));
21
22 // CHECK-LABEL: define dso_local void @test_redecl(
23 // CHECK: {{.*}} = call i32 (ptr, ...) @redecl(ptr noundef @.str) #[[ATTR_DUPE_IDENTICAL:[0-9]+]]
24 void test_redecl(void) {
25 redecl("hello");
26 }
27
28 int order1(const char *fmt, ...) __attribute__((modular_format(__modular_printf, "__printf", "a", "b"), format(printf, 1, 2)));
29 int order2(const char *fmt, ...) __attribute__((modular_format(__modular_printf, "__printf", "b", "a"), format(printf, 1, 2)));
30
31 // CHECK-LABEL: define dso_local void @test_order(
32 // CHECK: {{.*}} = call i32 (ptr, ...) @order1(ptr noundef @.str) #[[ATTR_ORDER:[0-9]+]]
33 // CHECK: {{.*}} = call i32 (ptr, ...) @order2(ptr noundef @.str) #[[ATTR_ORDER]]
34 void test_order(void) {
35 order1("hello");
36 order2("hello");
37 }
38
39 int duplicate_identical(const char *fmt, ...) __attribute__((modular_format(__dupe_impl, "__dupe", "1"), modular_format(__dupe_impl, "__dupe", "1"), format(printf, 1, 2)));
40
41 // CHECK-LABEL: define dso_local void @test_duplicate_identical(
42 // CHECK: {{.*}} = call i32 (ptr, ...) @duplicate_identical(ptr noundef @.str) #[[ATTR_DUPE_IDENTICAL]]
43 void test_duplicate_identical(void) {
44 duplicate_identical("hello");
45 }
46
47 // CHECK: attributes #[[ATTR]] = { "modular-format"="printf,1,2,__modular_printf,__printf,float" }
48 // CHECK: attributes #[[ATTR_DUPE_IDENTICAL]] = { "modular-format"="printf,1,2,__dupe_impl,__dupe,1" }
49 // CHECK: attributes #[[ATTR_ORDER]] = { "modular-format"="printf,1,2,__modular_printf,__printf,a,b" }