Skip to content

Commit

Permalink
The compiler is crashing when compiling a coroutine intrinsic without
Browse files Browse the repository at this point in the history
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
  • Loading branch information
zahiraam committed May 27, 2021
1 parent 08d31ff commit a4b61c8
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 20 deletions.
32 changes: 16 additions & 16 deletions clang/include/clang/Basic/Builtins.def
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions clang/include/clang/Basic/Builtins.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 7 additions & 4 deletions clang/lib/Basic/Builtins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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
Expand Down
19 changes: 19 additions & 0 deletions clang/test/SemaCXX/coroutine-builtins.cpp
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit a4b61c8

Please sign in to comment.