diff --git a/clang/lib/DPCT/Diagnostics/Diagnostics.inc b/clang/lib/DPCT/Diagnostics/Diagnostics.inc index ff34651e9121..a0bc99f2a280 100644 --- a/clang/lib/DPCT/Diagnostics/Diagnostics.inc +++ b/clang/lib/DPCT/Diagnostics/Diagnostics.inc @@ -58,8 +58,8 @@ DEF_WARNING(TIME_MEASUREMENT_FOUND, 1012, MEDIUM_LEVEL, "Detected kernel executi DEF_COMMENT(TIME_MEASUREMENT_FOUND, 1012, MEDIUM_LEVEL, "Detected kernel execution time measurement pattern and generated an initial code for time measurements in SYCL. You can change the way time is measured depending on your goals.") DEF_WARNING(ROUNDING_MODE_UNSUPPORTED, 1013, MEDIUM_LEVEL, "The rounding mode could not be specified and the generated code may have different accuracy than the original code. Verify the correctness. SYCL math built-in function rounding mode is aligned with OpenCL C 1.2 standard.") DEF_COMMENT(ROUNDING_MODE_UNSUPPORTED, 1013, MEDIUM_LEVEL, "The rounding mode could not be specified and the generated code may have different accuracy than the original code. Verify the correctness. SYCL math built-in function rounding mode is aligned with OpenCL C 1.2 standard.") -DEF_WARNING(STREAM_FLAG_PRIORITY_NOT_SUPPORTED, 1014, MEDIUM_LEVEL, "The flag and priority options are not supported for SYCL queues. The output parameter(s) are set to 0.") -DEF_COMMENT(STREAM_FLAG_PRIORITY_NOT_SUPPORTED, 1014, MEDIUM_LEVEL, "The flag and priority options are not supported for SYCL queues. The output parameter(s) are set to 0.") +DEF_WARNING(UNSUPPORTED_FEATURE_IN_SYCL, 1014, MEDIUM_LEVEL, "The %0 %1 not supported for SYCL %2. The output parameter(s) %1 set to 0.") +DEF_COMMENT(UNSUPPORTED_FEATURE_IN_SYCL, 1014, MEDIUM_LEVEL, "The {0} {1} not supported for SYCL {2}. The output parameter(s) {1} set to 0.") DEF_WARNING(PRINTF_FUNC_MIGRATION_WARNING, 1015, LOW_LEVEL, "Output needs adjustment.") DEF_COMMENT(PRINTF_FUNC_MIGRATION_WARNING, 1015, LOW_LEVEL, "Output needs adjustment.") DEF_WARNING(NOT_SUPPORTED_PARAMETERS_VALUE, 1016, LOW_LEVEL, "deprecated") diff --git a/clang/lib/DPCT/RulesLang/RulesLang.cpp b/clang/lib/DPCT/RulesLang/RulesLang.cpp index e0f0fb8cda88..2d92933b3481 100644 --- a/clang/lib/DPCT/RulesLang/RulesLang.cpp +++ b/clang/lib/DPCT/RulesLang/RulesLang.cpp @@ -2569,6 +2569,10 @@ void EventAPICallRule::registerMatcher(MatchFinder &MF) { unless(parentStmt()))) .bind("eventAPICallUsed"), this); + MF.addMatcher(declRefExpr(to(enumConstantDecl(hasType( + enumDecl(hasName("CUevent_flags_enum")))))) + .bind("eventEnum"), + this); } bool isEqualOperator(const Stmt *S) { @@ -2879,6 +2883,16 @@ bool EventAPICallRule::isEventElapsedTimeFollowed(const CallExpr *Expr) { } void EventAPICallRule::runRule(const MatchFinder::MatchResult &Result) { + if (auto *DRE = getNodeAsType(Result, "eventEnum")) { + if (auto *EC = dyn_cast(DRE->getDecl())) { + std::string EName = EC->getName().str(); + report(DRE->getBeginLoc(), Diagnostics::UNSUPPORTED_FEATURE_IN_SYCL, + false, EName, "is", "event"); + emplaceTransformation(new ReplaceStmt(DRE, "0")); + } + return; + } + bool IsAssigned = false; const CallExpr *CE = getNodeAsType(Result, "eventAPICall"); if (!CE) { @@ -4247,8 +4261,8 @@ void StreamAPICallRule::runRule(const MatchFinder::MatchResult &Result) { emplaceTransformation(new ReplaceStmt(CE, ReplStr)); } else if (FuncName == "cudaStreamGetFlags" || FuncName == "cudaStreamGetPriority") { - report(CE->getBeginLoc(), Diagnostics::STREAM_FLAG_PRIORITY_NOT_SUPPORTED, - false); + report(CE->getBeginLoc(), Diagnostics::UNSUPPORTED_FEATURE_IN_SYCL, false, + "flag and priority options", "are", "queues"); auto StmtStr1 = getStmtSpelling(CE->getArg(1)); std::string ReplStr{"*("}; ReplStr += StmtStr1; diff --git a/clang/test/dpct/driver-stream-and-event.cu b/clang/test/dpct/driver-stream-and-event.cu index fae2a6d1b69e..901806d3f02b 100644 --- a/clang/test/dpct/driver-stream-and-event.cu +++ b/clang/test/dpct/driver-stream-and-event.cu @@ -161,3 +161,20 @@ void test_cuEventRecord_crash(CUevent hEvent, CUstream hStream) // CHECK: int result = DPCT_CHECK_ERROR(*(dpct::event_ptr)hEvent = ((dpct::queue_ptr)hStream)->ext_oneapi_submit_barrier()); CUresult result = cuEventRecord((CUevent)hEvent, (CUstream)hStream); } + +unsigned getEventFlags(bool enabledSyncBlock) { + // CHECK: /* + // CHECK-NEXT: DPCT1014:{{[0-9]+}}: The CU_EVENT_DISABLE_TIMING is not supported for SYCL event. The output parameter(s) is set to 0. + // CHECK-NEXT: */ + // CHECK-NEXT: unsigned flags = 0; + unsigned flags = CU_EVENT_DISABLE_TIMING; + + if (enabledSyncBlock) + // CHECK: /* + // CHECK-NEXT: DPCT1014:{{[0-9]+}}: The CU_EVENT_BLOCKING_SYNC is not supported for SYCL event. The output parameter(s) is set to 0. + // CHECK-NEXT: */ + // CHECK-NEXT: flags |= 0; + flags |= CU_EVENT_BLOCKING_SYNC; + + return flags; +}