llvm
e91f5545 - [SYCL][UB] Make `Command::isHostTask()` virtual instead of downcasting on `MType` (#23081)

Commit
37 days ago
[SYCL][UB] Make `Command::isHostTask()` virtual instead of downcasting on `MType` (#23081) ## Problem `Command::isHostTask()` deduced the dynamic type of the command from its type tag and then downcast unconditionally: ```cpp bool Command::isHostTask() const { return (MType == CommandType::RUN_CG) /* host task has this type also */ && ((static_cast<const ExecCGCommand *>(this))->getCG().getType() == CGType::CodeplayHostTask); } ``` `static_cast` to a derived type is undefined behaviour unless the object really is of that type; nothing in the type system enforces `RUN_CG => ExecCGCommand`, only convention. When the object is a plain `Command` subobject, `getCG()` reads `MCommandGroup` from beyond the end of the allocation. AddressSanitizer report (ASan+UBSan build, `SchedulerTest.DontEnqueueDepsIfOneOfThemIsBlocked`): ``` ERROR: AddressSanitizer: global-buffer-overflow on address ... READ of size 4 at ... thread T0 #0 ... in getType sycl/source/detail/cg.hpp:104 #1 ... in sycl::_V1::detail::Command::isHostTask() const sycl/source/detail/scheduler/commands.cpp:246 #2 ... in isBlocking sycl/source/detail/scheduler/commands.hpp:178 #3 ... in Scheduler::GraphProcessor::handleBlockingCmd(...) ``` --- Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Author
Parents
Loading