diff --git a/clang/include/clang/Basic/Builtins.def b/clang/include/clang/Basic/Builtins.def --- a/clang/include/clang/Basic/Builtins.def +++ b/clang/include/clang/Basic/Builtins.def @@ -559,6 +559,7 @@ BUILTIN(__builtin_bzero, "vv*z", "nF") BUILTIN(__builtin_fprintf, "iP*cC*.", "Fp:1:") BUILTIN(__builtin_free, "vv*", "nF") +BUILTIN(__builtin_fscanf, "iP*RcC*R.", "Fs:1:") BUILTIN(__builtin_malloc, "v*z", "nF") BUILTIN(__builtin_memchr, "v*vC*iz", "nFE") BUILTIN(__builtin_memcmp, "ivC*vC*z", "nFE") @@ -569,6 +570,10 @@ BUILTIN(__builtin_memset, "v*v*iz", "nF") BUILTIN(__builtin_memset_inline, "vv*iIz", "n") BUILTIN(__builtin_printf, "icC*.", "Fp:0:") +BUILTIN(__builtin_scanf, "icC*R.", "Fs:0:") +BUILTIN(__builtin_snprintf, "ic*zcC*.", "nFp:2:") +BUILTIN(__builtin_sprintf, "ic*cC*.", "nFP:1:") +BUILTIN(__builtin_sscanf, "icC*RcC*R.", "Fs:1:") BUILTIN(__builtin_stpcpy, "c*c*cC*", "nF") BUILTIN(__builtin_stpncpy, "c*c*cC*z", "nF") BUILTIN(__builtin_strcasecmp, "icC*cC*", "nF") @@ -605,8 +610,11 @@ BUILTIN(__builtin_longjmp, "vv**i", "r") BUILTIN(__builtin_unwind_init, "v", "") BUILTIN(__builtin_eh_return_data_regno, "iIi", "ncE") -BUILTIN(__builtin_snprintf, "ic*zcC*.", "nFp:2:") -BUILTIN(__builtin_sprintf, "ic*cC*.", "nFP:1:") +BUILTIN(__builtin_vfprintf, "iP*cC*a", "FP:1:") +BUILTIN(__builtin_vfscanf, "iP*RcC*Ra", "FS:1:") +BUILTIN(__builtin_vprintf, "icC*a", "FP:0:") +BUILTIN(__builtin_vscanf, "icC*Ra", "FS:0:") +BUILTIN(__builtin_vsscanf, "icC*RcC*Ra", "FS:1:") BUILTIN(__builtin_vsnprintf, "ic*zcC*a", "nFP:2:") BUILTIN(__builtin_vsprintf, "ic*cC*a", "nFP:1:") BUILTIN(__builtin_thread_pointer, "v*", "nc") diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -100,12 +100,27 @@ // TODO: This list should be expanded or refactored after all GCC-compatible // std libcall builtins are implemented. static SmallDenseMap F128Builtins{ + {Builtin::BI__builtin___fprintf_chk, "__fprintfieee128"}, + {Builtin::BI__builtin___printf_chk, "__printfieee128"}, + {Builtin::BI__builtin___snprintf_chk, "__snprintfieee128"}, + {Builtin::BI__builtin___sprintf_chk, "__sprintfieee128"}, + {Builtin::BI__builtin___vfprintf_chk, "__vfprintfieee128"}, + {Builtin::BI__builtin___vsnprintf_chk, "__vsnprintfieee128"}, + {Builtin::BI__builtin___vsprintf_chk, "__vsprintfieee128"}, + {Builtin::BI__builtin_fprintf, "__fprintfieee128"}, + {Builtin::BI__builtin_fscanf, "__fscanfieee128"}, {Builtin::BI__builtin_printf, "__printfieee128"}, + {Builtin::BI__builtin_scanf, "__scanfieee128"}, + {Builtin::BI__builtin_snprintf, "__snprintfieee128"}, + {Builtin::BI__builtin_sprintf, "__sprintfieee128"}, + {Builtin::BI__builtin_sscanf, "__sscanfieee128"}, + {Builtin::BI__builtin_vfprintf, "__vfprintfieee128"}, + {Builtin::BI__builtin_vfscanf, "__vfscanfieee128"}, + {Builtin::BI__builtin_vprintf, "__vprintfieee128"}, + {Builtin::BI__builtin_vscanf, "__vscanfieee128"}, {Builtin::BI__builtin_vsnprintf, "__vsnprintfieee128"}, {Builtin::BI__builtin_vsprintf, "__vsprintfieee128"}, - {Builtin::BI__builtin_sprintf, "__sprintfieee128"}, - {Builtin::BI__builtin_snprintf, "__snprintfieee128"}, - {Builtin::BI__builtin_fprintf, "__fprintfieee128"}, + {Builtin::BI__builtin_vsscanf, "__vsscanfieee128"}, {Builtin::BI__builtin_nexttowardf128, "__nexttowardieee128"}, }; diff --git a/clang/test/CodeGen/PowerPC/ppc64-f128-builtins.c b/clang/test/CodeGen/PowerPC/ppc64-f128-builtins.c --- a/clang/test/CodeGen/PowerPC/ppc64-f128-builtins.c +++ b/clang/test/CodeGen/PowerPC/ppc64-f128-builtins.c @@ -61,3 +61,52 @@ long double test_nexttoward(long double a, long double b) { return __builtin_nexttowardl(a, b); } + +// IEEE128-LABEL: define dso_local void @test_scanf +// IEEE128: call signext i32 (ptr, ...) @__scanfieee128 +// PPC128-LABEL: define dso_local void @test_scanf +// PPC128: call signext i32 (ptr, ...) @scanf +void test_scanf(int *x) { + __builtin_scanf("%d", x); +} + +// IEEE128-LABEL: define dso_local void @test_sscanf +// IEEE128: call signext i32 (ptr, ptr, ...) @__sscanfieee128 +// PPC128-LABEL: define dso_local void @test_sscanf +// PPC128: call signext i32 (ptr, ptr, ...) @sscanf +void test_sscanf(int *x) { + __builtin_sscanf(buf, "%d", x); +} + +// IEEE128-LABEL: define dso_local void @test_vprintf +// IEEE128: call signext i32 @__vprintfieee128 +// PPC128-LABEL: define dso_local void @test_vprintf +// PPC128: call signext i32 @vprintf +void test_vprintf(const char *fmt, ...) { + __builtin_va_list args; + __builtin_va_start(args, fmt); + __builtin_vprintf(fmt, args); + __builtin_va_end(args); +} + +// IEEE128-LABEL: define dso_local void @test_vscanf +// IEEE128: call signext i32 @__vscanfieee128 +// PPC128-LABEL: define dso_local void @test_vscanf +// PPC128: call signext i32 @vscanf +void test_vscanf(const char *fmt, ...) { + __builtin_va_list args; + __builtin_va_start(args, fmt); + __builtin_vscanf(fmt, args); + __builtin_va_end(args); +} + +// IEEE128-LABEL: define dso_local void @test_vsscanf +// IEEE128: call signext i32 @__vsscanfieee128 +// PPC128-LABEL: define dso_local void @test_vsscanf +// PPC128: call signext i32 @vsscanf +void test_vsscanf(const char *fmt, ...) { + __builtin_va_list args; + __builtin_va_start(args, fmt); + __builtin_vsscanf(buf, fmt, args); + __builtin_va_end(args); +}