Repository navigation
release: pure functions returning owned memory no longer double free - #4248
Merged
Merged
Conversation
…ptimizer merge calls; pure methods cannot write this
|
Caution Review failedThe pull request is closed.
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4243.
Calling a
purefunction that returns astrtwice with the same argument could free the same memory twice.purebecame__attribute__((pure))in C andmemory(read) willreturnin LLVM, which lets the optimizer merge two calls into one; but each call returns a new string that the caller frees, so after the merge both temporaries pointed at the same allocation.str.Trim,str.Substrandstr.Concatarepure, so plain input validation crashed (default backend,--backend=llvm, and C with clang).sm.PureAttrOk, before emitting those attributes: they are kept only when the return type is a plain scalar (numbers, bool, char, enums). Apurefunction returningstr, a vector, a map, a struct or anything else that may own memory still compiles and keeps its purity checks, but its calls are never merged.purefunction that writes a global, writes through a parameter or calls something impure. It now also rejects apuremethod that assigns to a field ofthis(E013, English and Persian messages). No stdpuremethod does that today.Tests:
general/pure_heap_returns(en, fa) calls user and stdpurefunctions returningstrandVectorseveral times in one expression;errors/pure_write_this(en, fa) checks the new error;codegen_testandllvm_testcheck thatstrandVectorreturns lose the attributes whileintkeeps them.Verified on macOS arm64: both programs from the issue crash with 0.7.0 on all three backends and print
true/donewith this branch.