-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conditional allocations shouldn't fail if cond=false, size=0 -> nullptr result #7255
Comments
This may be an issue unique to the C backend, if that's where you observed this. I see code that handles this in CodeGen_Posix.cpp:307 |
Yep. That logic looks simpler than what I have for a fix, I'll try replicating that instead. Fix on the way either way. |
Allocations can be conditional; if the condition evaluates to false, we end up calling `halide_malloc(0)` (or `halide_tcm_malloc(0)` in the xtensa branch). Since it's legal via spec for `malloc(0)` to return nullptr, we need to be cautious here: if we are compiling with assertions enabled, *and* have a malloc() (etc) implementation that returns nullptr for alloc(0), we need to skip the assertion check, since we know the result won't be used. Note: a similar check will be inserted in the xtensa branch separately. Note 2: LLVM backend already has this check via Codegen_Posix.cpp
FYI: via inserting a crash at Codegen_Posix.cpp:298 and rebuilding the universe, I can't find a single AOT case in our tests that actually triggers the |
…) (#7256) * Conditional allocations shouldn't fail for size=0 in C++ backend (#7255) Allocations can be conditional; if the condition evaluates to false, we end up calling `halide_malloc(0)` (or `halide_tcm_malloc(0)` in the xtensa branch). Since it's legal via spec for `malloc(0)` to return nullptr, we need to be cautious here: if we are compiling with assertions enabled, *and* have a malloc() (etc) implementation that returns nullptr for alloc(0), we need to skip the assertion check, since we know the result won't be used. Note: a similar check will be inserted in the xtensa branch separately. Note 2: LLVM backend already has this check via Codegen_Posix.cpp * Update CodeGen_C.cpp
…ide#7255) (halide#7256) * Conditional allocations shouldn't fail for size=0 in C++ backend (halide#7255) Allocations can be conditional; if the condition evaluates to false, we end up calling `halide_malloc(0)` (or `halide_tcm_malloc(0)` in the xtensa branch). Since it's legal via spec for `malloc(0)` to return nullptr, we need to be cautious here: if we are compiling with assertions enabled, *and* have a malloc() (etc) implementation that returns nullptr for alloc(0), we need to skip the assertion check, since we know the result won't be used. Note: a similar check will be inserted in the xtensa branch separately. Note 2: LLVM backend already has this check via Codegen_Posix.cpp * Update CodeGen_C.cpp
Allocations can be conditional; if the condition evaluates to false, we end up calling
halide_malloc(0)
. Since it's legal via spec formalloc(0)
to return nullptr, we need to be cautious here: if we are compiling with assertions enabled, and have a malloc() (etc) implementation that returns nullptr for alloc(0), we need to skip the assertion check, since we know the result won't be used... but the assertion would fail because the (ignored) result is null.NOTE: I've only seen this in the C++ backend; so far, I can't replicate it with LLVM backends.
The text was updated successfully, but these errors were encountered: