Author: Zahira Ammarguellat Date: 2021-05-26T18:07:31-07:00 New Revision: a4b61c82cf1a45c172af2e0242f5019281de14f8
URL: https://github.com/llvm/llvm-project/commit/a4b61c82cf1a45c172af2e0242f5019281de14f8 DIFF: https://github.com/llvm/llvm-project/commit/a4b61c82cf1a45c172af2e0242f5019281de14f8.diff LOG: The compiler is crashing when compiling a coroutine intrinsic without the use of the option fcoroutines-ts. This is a patch to fix this. Fix for https://bugs.llvm.org/show_bug.cgi?id=50406 Added: clang/test/SemaCXX/coroutine-builtins.cpp Modified: clang/include/clang/Basic/Builtins.def clang/include/clang/Basic/Builtins.h clang/lib/Basic/Builtins.cpp Removed: ################################################################################ diff --git a/clang/include/clang/Basic/Builtins.def b/clang/include/clang/Basic/Builtins.def index ead84e2e6279..5a9d0a001829 100644 --- a/clang/include/clang/Basic/Builtins.def +++ b/clang/include/clang/Basic/Builtins.def @@ -1577,22 +1577,22 @@ BUILTIN(__builtin_nontemporal_store, "v.", "t") 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. diff --git a/clang/include/clang/Basic/Builtins.h b/clang/include/clang/Basic/Builtins.h index eefe549b4fa8..cdaaee48c32d 100644 --- a/clang/include/clang/Basic/Builtins.h +++ b/clang/include/clang/Basic/Builtins.h @@ -37,6 +37,7 @@ enum LanguageID { 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. diff --git a/clang/lib/Basic/Builtins.cpp b/clang/lib/Basic/Builtins.cpp index 8a70c7eed530..7118aa9dc210 100644 --- a/clang/lib/Basic/Builtins.cpp +++ b/clang/lib/Basic/Builtins.cpp @@ -60,6 +60,8 @@ bool Builtin::Context::builtinIsSupported(const Builtin::Info &BuiltinInfo, 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 Builtin::Context::builtinIsSupported(const Builtin::Info &BuiltinInfo, 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 diff --git a/clang/test/SemaCXX/coroutine-builtins.cpp b/clang/test/SemaCXX/coroutine-builtins.cpp new file mode 100644 index 000000000000..927faf6974b9 --- /dev/null +++ b/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 +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits