@@ -61,6 +61,8 @@ static constexpr llvm::StringLiteral InitESIMDMethodName = "__init_esimd";
61
61
static constexpr llvm::StringLiteral InitSpecConstantsBuffer =
62
62
" __init_specialization_constants_buffer" ;
63
63
static constexpr llvm::StringLiteral FinalizeMethodName = " __finalize" ;
64
+ static constexpr llvm::StringLiteral LibstdcxxFailedAssertion =
65
+ " __failed_assertion" ;
64
66
constexpr unsigned MaxKernelArgsSize = 2048 ;
65
67
66
68
namespace {
@@ -320,6 +322,21 @@ static bool isSYCLKernelBodyFunction(FunctionDecl *FD) {
320
322
return FD->getOverloadedOperator () == OO_Call;
321
323
}
322
324
325
+ static bool isSYCLUndefinedAllowed (const FunctionDecl *Callee,
326
+ const SourceManager &SrcMgr) {
327
+ if (!Callee)
328
+ return false ;
329
+
330
+ // libstdc++-11 introduced an undefined function "void __failed_assertion()"
331
+ // which may lead to SemaSYCL check failure. However, this undefined function
332
+ // is used to trigger some compilation error when the check fails at compile
333
+ // time and will be ignored when the check succeeds. We allow calls to this
334
+ // function to support some important std functions in SYCL device.
335
+ return (Callee->getName () == LibstdcxxFailedAssertion) &&
336
+ Callee->getNumParams () == 0 && Callee->getReturnType ()->isVoidType () &&
337
+ SrcMgr.isInSystemHeader (Callee->getLocation ());
338
+ }
339
+
323
340
// Helper function to report conflicting function attributes.
324
341
// F - the function, A1 - function attribute, A2 - the attribute it conflicts
325
342
// with.
@@ -4034,7 +4051,10 @@ void Sema::finalizeSYCLDelayedAnalysis(const FunctionDecl *Caller,
4034
4051
return ;
4035
4052
4036
4053
// Diagnose if this is an undefined function and it is not a builtin.
4037
- if (!Callee->isDefined () && !Callee->getBuiltinID ()) {
4054
+ // Currently, there is an exception of "__failed_assertion" in libstdc++-11,
4055
+ // this undefined function is used to trigger a compiling error.
4056
+ if (!Callee->isDefined () && !Callee->getBuiltinID () &&
4057
+ !isSYCLUndefinedAllowed (Callee, getSourceManager ())) {
4038
4058
Diag (Loc, diag::err_sycl_restrict) << Sema::KernelCallUndefinedFunction;
4039
4059
Diag (Callee->getLocation (), diag::note_previous_decl) << Callee;
4040
4060
Diag (Caller->getLocation (), diag::note_called_by) << Caller;
0 commit comments