Skip to content
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 for size=0 in C++ backend (#7255) #7256

Merged
merged 2 commits into from
Dec 28, 2022

Conversation

steven-johnson
Copy link
Contributor

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

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
@steven-johnson steven-johnson merged commit 04bb986 into main Dec 28, 2022
@steven-johnson steven-johnson deleted the srj/conditional-allocs branch December 28, 2022 17:31
ardier pushed a commit to ardier/Halide-mutation that referenced this pull request Mar 3, 2024
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants