Index: clang/include/clang/Basic/Builtins.h =================================================================== --- clang/include/clang/Basic/Builtins.h +++ clang/include/clang/Basic/Builtins.h @@ -37,6 +37,7 @@ OCLC1X_LANG = 0x40, // builtin for OpenCL C 1.x only. OMP_LANG = 0x80, // builtin requires OpenMP. CUDA_LANG = 0x100, // builtin requires CUDA. + COR_LANG = 0x200, // builtin requires use of 'fcoroutine-ts' option. ALL_LANGUAGES = C_LANG | CXX_LANG | OBJC_LANG, // builtin for all languages. ALL_GNU_LANGUAGES = ALL_LANGUAGES | GNU_LANG, // builtin requires GNU mode. ALL_MS_LANGUAGES = ALL_LANGUAGES | MS_LANG, // builtin requires MS mode. Index: clang/include/clang/Basic/Builtins.def =================================================================== --- clang/include/clang/Basic/Builtins.def +++ clang/include/clang/Basic/Builtins.def @@ -1577,22 +1577,22 @@ BUILTIN(__builtin_nontemporal_load, "v.", "t") // Coroutine intrinsics. -BUILTIN(__builtin_coro_resume, "vv*", "") -BUILTIN(__builtin_coro_destroy, "vv*", "") -BUILTIN(__builtin_coro_done, "bv*", "n") -BUILTIN(__builtin_coro_promise, "v*v*IiIb", "n") - -BUILTIN(__builtin_coro_size, "z", "n") -BUILTIN(__builtin_coro_frame, "v*", "n") -BUILTIN(__builtin_coro_noop, "v*", "n") -BUILTIN(__builtin_coro_free, "v*v*", "n") - -BUILTIN(__builtin_coro_id, "v*Iiv*v*v*", "n") -BUILTIN(__builtin_coro_alloc, "b", "n") -BUILTIN(__builtin_coro_begin, "v*v*", "n") -BUILTIN(__builtin_coro_end, "bv*Ib", "n") -BUILTIN(__builtin_coro_suspend, "cIb", "n") -BUILTIN(__builtin_coro_param, "bv*v*", "n") +LANGBUILTIN(__builtin_coro_resume, "vv*", "", COR_LANG) +LANGBUILTIN(__builtin_coro_destroy, "vv*", "", COR_LANG) +LANGBUILTIN(__builtin_coro_done, "bv*", "n", COR_LANG) +LANGBUILTIN(__builtin_coro_promise, "v*v*IiIb", "n", COR_LANG) + +LANGBUILTIN(__builtin_coro_size, "z", "n", COR_LANG) +LANGBUILTIN(__builtin_coro_frame, "v*", "n", COR_LANG) +LANGBUILTIN(__builtin_coro_noop, "v*", "n", COR_LANG) +LANGBUILTIN(__builtin_coro_free, "v*v*", "n", COR_LANG) + +LANGBUILTIN(__builtin_coro_id, "v*Iiv*v*v*", "n", COR_LANG) +LANGBUILTIN(__builtin_coro_alloc, "b", "n", COR_LANG) +LANGBUILTIN(__builtin_coro_begin, "v*v*", "n", COR_LANG) +LANGBUILTIN(__builtin_coro_end, "bv*Ib", "n", COR_LANG) +LANGBUILTIN(__builtin_coro_suspend, "cIb", "n", COR_LANG) +LANGBUILTIN(__builtin_coro_param, "bv*v*", "n", COR_LANG) // OpenCL v2.0 s6.13.16, s9.17.3.5 - Pipe functions. // We need the generic prototype, since the packet type could be anything. Index: clang/lib/Basic/Builtins.cpp =================================================================== --- clang/lib/Basic/Builtins.cpp +++ clang/lib/Basic/Builtins.cpp @@ -60,6 +60,8 @@ bool BuiltinsUnsupported = (LangOpts.NoBuiltin || LangOpts.isNoBuiltinFunc(BuiltinInfo.Name)) && strchr(BuiltinInfo.Attributes, 'f'); + bool CorBuiltinsUnsupported = + !LangOpts.Coroutines && (BuiltinInfo.Langs & COR_LANG); bool MathBuiltinsUnsupported = LangOpts.NoMathBuiltin && BuiltinInfo.HeaderName && llvm::StringRef(BuiltinInfo.HeaderName).equals("math.h"); @@ -78,10 +80,11 @@ bool CUDAUnsupported = !LangOpts.CUDA && BuiltinInfo.Langs == CUDA_LANG; bool CPlusPlusUnsupported = !LangOpts.CPlusPlus && BuiltinInfo.Langs == CXX_LANG; - return !BuiltinsUnsupported && !MathBuiltinsUnsupported && !OclCUnsupported && - !OclC1Unsupported && !OclC2Unsupported && !OpenMPUnsupported && - !GnuModeUnsupported && !MSModeUnsupported && !ObjCUnsupported && - !CPlusPlusUnsupported && !CUDAUnsupported; + return !BuiltinsUnsupported && !CorBuiltinsUnsupported && + !MathBuiltinsUnsupported && !OclCUnsupported && !OclC1Unsupported && + !OclC2Unsupported && !OpenMPUnsupported && !GnuModeUnsupported && + !MSModeUnsupported && !ObjCUnsupported && !CPlusPlusUnsupported && + !CUDAUnsupported; } /// initializeBuiltins - Mark the identifiers for all the builtins with their Index: clang/test/SemaCXX/coroutine-builtins.cpp =================================================================== --- /dev/null +++ clang/test/SemaCXX/coroutine-builtins.cpp @@ -0,0 +1,19 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -fcoroutines-ts %s +// RUN: %clang_cc1 -fsyntax-only -verify -DERRORS %s + +// Check that we don't crash when using __builtin_coro_* without the fcoroutine-ts option + +#ifdef ERRORS +// expected-error@#A{{use of undeclared identifier '__builtin_coro_done'}} +// expected-error@#B{{use of undeclared identifier '__builtin_coro_id'}} +// expected-error@#C{{use of undeclared identifier '__builtin_coro_alloc'}} +#else +// expected-no-diagnostics +#endif + +int main() { + void *co_h; + bool d = __builtin_coro_done(co_h); // #A + __builtin_coro_id(32, 0, 0, 0); // #B + __builtin_coro_alloc(); // #C +}