Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upPassing enum by-value loses range metadata #13926
Comments
huonw
added
the
I-slow
label
May 4, 2014
huonw
changed the title
Indexing fixed-length array be shorter enum doesn't eliminate bounds checks
Indexing fixed-length array with shorter enum doesn't eliminate bounds checks
May 4, 2014
This comment has been minimized.
This comment has been minimized.
|
Oh, actually: this is because there is no range metadata when define i64 @_ZN3foo20h043091a9d9208cb0saa4v0.0E(i8* nocapture readonly) unnamed_addr #0 {
entry-block:
%1 = load i8* %0, align 1, !range !0
%2 = zext i8 %1 to i64
%3 = getelementptr inbounds [4 x i64]* @_ZN1X20hcca41332b11ffec7iaa4v0.0E, i64 0, i64 %2
%4 = load i64* %3, align 8
ret i64 %4
}
!0 = metadata !{i8 0, i8 4}Updated title from "indexing fixed-length array doesn't eliminated bounds checks". |
huonw
changed the title
Indexing fixed-length array with shorter enum doesn't eliminate bounds checks
Passing enum by-value loses range metadata
May 4, 2014
This comment has been minimized.
This comment has been minimized.
|
Fixing this would likely require extending the feature in LLVM to be usable on parameters. |
thestinger
added
A-LLVM
B-upstream
labels
Oct 28, 2014
This comment has been minimized.
This comment has been minimized.
|
I agree that the |
alexcrichton
removed
the
B-upstream
label
Aug 11, 2015
This comment has been minimized.
This comment has been minimized.
|
If the enumeration derives pub fn foo(y: Foo) -> isize {
let closure = |z: &Foo| { X[(*z) as usize] };
closure(&y)
}; Function Attrs: nounwind readnone uwtable
define i64 @_ZN3foo20h8ac558f51be88dd53aaE(i8) unnamed_addr #1 {
entry-block:
%1 = zext i8 %0 to i64
%2 = getelementptr inbounds [4 x i64], [4 x i64]* @_ZN1X20h5e497aaeb62c0700UaaE, i64 0, i64 %1
%3 = load i64, i64* %2, align 8, !noalias !1
ret i64 %3
}This might be fragile as it probably relies on the order in which the LLVM optimiser performs the bound-check optimisation and the closure inlining. |
brson
added
P-low
T-compiler
labels
Mar 9, 2017
This comment has been minimized.
This comment has been minimized.
|
Can this be reproed today? |
This comment has been minimized.
This comment has been minimized.
|
|
huonw commentedMay 4, 2014
becomes
even though it's impossible for a
Footo be larger than 3, so the bounds checking can never fail. (Doing a similar thing with e.g.[int, .. 256]and a value of typeu8does eliminate the bounds checks.)(I guess this is an LLVM bug, but filing it here just in case we're emiting range info incorrectly, or some-such.)