diff --git a/include/clang/Basic/Builtins.def b/include/clang/Basic/Builtins.def index 247ffde019b3989225cf178d3d0d1621fdbe1cde..3dd25b4ebf32b3d5f635c1b3b5e0d8c00fd88d0e 100644 --- a/include/clang/Basic/Builtins.def +++ b/include/clang/Basic/Builtins.def @@ -70,6 +70,8 @@ // f -> this is a libc/libm function without the '__builtin_' prefix. It can // be followed by ':headername:' to state which header this function // comes from. +// i -> this is a runtime library implemented function without the +// '__builtin_' prefix. It will be implemented in compiter-rt or libgcc. // p:N: -> this is a printf-like function whose Nth argument is the format // string. // P:N: -> similar to the p:N: attribute, but the function is like vprintf diff --git a/include/clang/Basic/Builtins.h b/include/clang/Basic/Builtins.h index 77c0461f10620b012a55ad7e95117e344a5219b8..eb156519ae8b6e1d120ce4f45a622cd5891bb4ab 100644 --- a/include/clang/Basic/Builtins.h +++ b/include/clang/Basic/Builtins.h @@ -130,6 +130,13 @@ public: return strchr(GetRecord(ID).Attributes, 'f') != 0; } + /// \brief Determines whether this builtin is a predefined compiler-rt/libgcc + /// function, such as "__clear_cache", where we know the signature a + /// priori. + bool isPredefinedRuntimeFunction(unsigned ID) const { + return strchr(GetRecord(ID).Attributes, 'i') != 0; + } + /// \brief Determines whether this builtin has custom typechecking. bool hasCustomTypechecking(unsigned ID) const { return strchr(GetRecord(ID).Attributes, 't') != 0; diff --git a/include/clang/Basic/BuiltinsAArch64.def b/include/clang/Basic/BuiltinsAArch64.def index 9e9f6d0875dbfcd8a5db1fcc881f2d45bd997b3a..768e4bb26c7dc413aa0e8a18e0edfcc415e8e66c 100644 --- a/include/clang/Basic/BuiltinsAArch64.def +++ b/include/clang/Basic/BuiltinsAArch64.def @@ -15,4 +15,4 @@ // The format of this database matches clang/Basic/Builtins.def. // In libgcc -BUILTIN(__clear_cache, "vv*v*", "") +BUILTIN(__clear_cache, "vv*v*", "i") diff --git a/include/clang/Basic/BuiltinsARM.def b/include/clang/Basic/BuiltinsARM.def index fad9007e04b81ae044df955a629eefa581e2d22f..2f2993fc6aeaca43bad3a7638d4d83d362eb60ed 100644 --- a/include/clang/Basic/BuiltinsARM.def +++ b/include/clang/Basic/BuiltinsARM.def @@ -15,7 +15,7 @@ // The format of this database matches clang/Basic/Builtins.def. // In libgcc -BUILTIN(__clear_cache, "vv*v*", "") +BUILTIN(__clear_cache, "vv*v*", "i") BUILTIN(__builtin_thread_pointer, "v*", "") // Saturating arithmetic diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 00471816eb99153850141238c3b5a16217571642..e43a318804d21ee825f383d290e25518eadb5731 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -8687,7 +8687,8 @@ Decl *Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, Decl *D) { // Builtin functions cannot be defined. if (unsigned BuiltinID = FD->getBuiltinID()) { - if (!Context.BuiltinInfo.isPredefinedLibFunction(BuiltinID)) { + if (!Context.BuiltinInfo.isPredefinedLibFunction(BuiltinID) && + !Context.BuiltinInfo.isPredefinedRuntimeFunction(BuiltinID)) { Diag(FD->getLocation(), diag::err_builtin_definition) << FD; FD->setInvalidDecl(); } diff --git a/test/Sema/builtin-clear_cache.c b/test/Sema/builtin-clear_cache.c new file mode 100644 index 0000000000000000000000000000000000000000..e21aad79d12aa2b4d0f48c7a736b42ef54045133 --- /dev/null +++ b/test/Sema/builtin-clear_cache.c @@ -0,0 +1,5 @@ +// RUN: %clang_cc1 -triple armv7-none-linux-gnu -fsyntax-only -verify %s +// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -fsyntax-only -verify %s +// expected-no-diagnostics + +void __clear_cache(void *a, void *b) {}