panic branch does not get removed in presence of other function (that also does not get it removed) #119923
Labels
A-LLVM
Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.
C-bug
Category: This is a bug.
I-heavy
Issue: Problems and improvements with respect to binary size of generated code.
I-slow
Issue: Problems and improvements with respect to performance of generated code.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
I tried this code (compiler explorer):
and this code (compiler explorer):
(difference between the two is that
as_str_3
only exists in the first example)I expected to see this happen:
all
as_str_
functions compile to roughly the same code (no memory accesses, just some pointer addition and getting the length right)something like this (compiler explorer):
Instead, this happened:
as_str_1
became a switch table, so i pointed the compiler in the right direction withas_str_2
, i tried a few other things,as_str_3
with an integer division less but a byte longer string andas_str_4
with unsafe code to get the desired output.as_str_2
's panic branch only got removed when i commentedas_str_3
out,as_str_3
always had oneMeta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: