-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Unsoundness from premature drop of temporary in match scrutinee #10683
Comments
Note that the Servo bug seems to go away when optimization is enabled. |
Here's some relevant (?) disassembly with the local variable:
and without:
I can provide the |
use std::ascii::StrAsciiExt;
static NAME: &'static str = "hello world";
#[cfg(not(with_local))]
fn main() {
match NAME.to_ascii_lower().as_slice() {
"foo" => {}
_ => {}
}
}
#[cfg(with_local)]
fn main() {
let name = NAME.to_ascii_lower();
match name.as_slice() {
"foo" => {}
_ => {}
}
} seems to display the same problem, that is, when compiled without IR for ; Function Attrs: uwtable
define internal void @_ZN4main18hee8776918765f67an4v0.0E({ i64, %tydesc*, i8*, i8*, i8 }*) unnamed_addr #4 {
"function top level":
%name = alloca { i64, i64, [0 x i8] }*
%1 = alloca %str_slice
%2 = alloca { i8*, i32 }
%3 = alloca %str_slice
%4 = call { i64, i64, [0 x i8] }* @"_ZN5ascii26StrAsciiExt$__extensions__14to_ascii_lower20h4985d7ef49cc8d0zCaY4v0.0E"({ i64, %tydesc*, i8*, i8*, i8 }* bitcast ({ i8*, i64 }* @_ZN4NAME18h2f2e2b20757b714ah4v0.0E to { i64, %tydesc*, i8*, i8*, i8 }*))
store { i64, i64, [0 x i8] }* %4, { i64, i64, [0 x i8] }** %name
%5 = bitcast { i64, i64, [0 x i8] }** %name to { i64, %tydesc*, i8*, i8*, i8 }*
invoke void @"_ZN3str18Str$__extensions__8as_slice21h994e7dba4c3712c06vaL4v0.0E"(%str_slice* sret %1, { i64, %tydesc*, i8*, i8*, i8 }* %5)
to label %"normal return" unwind label %unwind
"normal return": ; preds = %"function top level"
%6 = getelementptr inbounds %str_slice* %3, i32 0, i32 0
store i8* getelementptr inbounds ([4 x i8]* @str1797, i32 0, i32 0), i8** %6
%7 = getelementptr inbounds %str_slice* %3, i32 0, i32 1
store i64 3, i64* %7
%8 = invoke i8 @_ZN3str8eq_slice19h85916ee1bf3841d9a84v0.0E({ i64, %tydesc*, i8*, i8*, i8 }* undef, %str_slice* %1, %str_slice* %3)
to label %"normal return2" unwind label %unwind
unwind: ; preds = %"normal return", %"function top level"
%9 = landingpad { i8*, i32 } personality i32 ()* @upcall_rust_personality
cleanup
call void @upcall_reset_stack_limit()
store { i8*, i32 } %9, { i8*, i32 }* %2
br label %cleanup
cleanup: ; preds = %unwind
call void @"_ZN8_$UP$str9glue_drop19h7187567e28f1bbb6aXE"({}* null, { i64, i64, [0 x i8] }** %name)
%10 = load { i8*, i32 }* %2
resume { i8*, i32 } %10
case_body: ; preds = %match_case
br label %join
case_body1: ; preds = %match_else
br label %join
match_else: ; preds = %compare_next
br label %case_body1
match_case: ; preds = %"normal return2"
br label %case_body
"normal return2": ; preds = %"normal return"
%11 = icmp ne i8 %8, 0
br i1 %11, label %match_case, label %compare_next
compare_next: ; preds = %"normal return2"
br label %match_else
join: ; preds = %case_body1, %case_body
call void @"_ZN8_$UP$str9glue_drop19h7187567e28f1bbb6aXE"({}* null, { i64, i64, [0 x i8] }** %name)
ret void
} without ; Function Attrs: uwtable
define internal void @_ZN4main18hee8776918765f67an4v0.0E({ i64, %tydesc*, i8*, i8*, i8 }*) unnamed_addr #4 {
"function top level":
%1 = alloca %str_slice
%2 = alloca { i64, i64, [0 x i8] }*
%3 = alloca { i64, i64, [0 x i8] }*
%4 = alloca { i8*, i32 }
%5 = alloca %str_slice
%6 = call { i64, i64, [0 x i8] }* @"_ZN5ascii26StrAsciiExt$__extensions__14to_ascii_lower20h4985d7ef49cc8d0zCa04v0.0E"({ i64, %tydesc*, i8*, i8*, i8 }* bitcast ({ i8*, i64 }* @_ZN4NAME18h2f2e2b20757b714ah4v0.0E to { i64, %tydesc*, i8*, i8*, i8 }*))
store { i64, i64, [0 x i8] }* %6, { i64, i64, [0 x i8] }** %2
%7 = load { i64, i64, [0 x i8] }** %2
store { i64, i64, [0 x i8] }* %7, { i64, i64, [0 x i8] }** %3
%8 = bitcast { i64, i64, [0 x i8] }** %3 to { i64, %tydesc*, i8*, i8*, i8 }*
invoke void @"_ZN3str18Str$__extensions__8as_slice21h994e7dba4c3712c06vaY4v0.0E"(%str_slice* sret %1, { i64, %tydesc*, i8*, i8*, i8 }* %8)
to label %"normal return" unwind label %unwind
"normal return": ; preds = %"function top level"
call void @"_ZN8_$UP$str9glue_drop19h7187567e28f1bbb6aYE"({}* null, { i64, i64, [0 x i8] }** %3)
%9 = getelementptr inbounds %str_slice* %5, i32 0, i32 0
store i8* getelementptr inbounds ([4 x i8]* @str1796, i32 0, i32 0), i8** %9
%10 = getelementptr inbounds %str_slice* %5, i32 0, i32 1
store i64 3, i64* %10
%11 = call i8 @_ZN3str8eq_slice19h85916ee1bf3841d9a34v0.0E({ i64, %tydesc*, i8*, i8*, i8 }* undef, %str_slice* %1, %str_slice* %5)
%12 = icmp ne i8 %11, 0
br i1 %12, label %match_case, label %compare_next
unwind: ; preds = %"function top level"
%13 = landingpad { i8*, i32 } personality i32 ()* @upcall_rust_personality
cleanup
call void @upcall_reset_stack_limit()
store { i8*, i32 } %13, { i8*, i32 }* %4
br label %cleanup
cleanup: ; preds = %unwind
call void @"_ZN8_$UP$str9glue_drop19h7187567e28f1bbb6aYE"({}* null, { i64, i64, [0 x i8] }** %3)
%14 = load { i8*, i32 }* %4
resume { i8*, i32 } %14
case_body: ; preds = %match_case
br label %join
case_body1: ; preds = %match_else
br label %join
match_else: ; preds = %compare_next
br label %case_body1
match_case: ; preds = %"normal return"
br label %case_body
compare_next: ; preds = %"normal return"
br label %match_else
join: ; preds = %case_body1, %case_body
ret void
} The key point being the positions of the |
The bug is rust-lang/rust#10683 and there's no fix yet, plus it would take us a while to upgrade Rust anyway. Fixes servo#1258.
The bug is rust-lang/rust#10683 and there's no fix yet, plus it would take us a while to upgrade Rust anyway. Fixes #1258.
cc me |
Fixed this issue ( rust-lang/rust#10683 )
This is not yet fixed, or at least not all fixed. For example, Rust master-ish with rust-encoding fails but only on OS X. Assigning the result of See here: https://github.com/mozilla-servo/rust-encoding/blob/master/src/label.rs#L14 |
pinging @hyunjunekim |
pong @metajack about this issue, What to have the problem in pull request (servo/servo#1388)? |
rust-encoding still crashes with this error even with your changes from #1388. Maybe more changes are needed? |
Can someone retest this easily with the latest rust master? (I don't have ready access to a rustc right at this moment) Quite possibly fixed by #3511 |
huonw's similar example seems to work now. But it would be good to check against the original bug. (And it might also be good to put huon's example as a regression test.) |
The bug is rust-lang/rust#10683 and there's no fix yet, plus it would take us a while to upgrade Rust anyway. Fixes servo#1258.
…S parse failure (from kmcallister:properties); r=jdm The bug is rust-lang/rust#10683 and there's no fix yet, plus it would take us a while to upgrade Rust anyway. Fixes #1258. Source-Repo: https://github.com/servo/servo Source-Revision: 148d1720e539c36ed44efdc7ebf3e45f25388f13 UltraBlame original commit: 28bc03c8fa39fea27af15f247cb7cc3c3f6fe31d
…unjunekim:cssissues); r=kmcallister Fixed this issue ( rust-lang/rust#10683 ) Source-Repo: https://github.com/servo/servo Source-Revision: c5d81f13c167ba46836b78359389e8d1a3f817d6 UltraBlame original commit: 19615f9ab014ee097b16427c1c85db9c1a353b6d
…S parse failure (from kmcallister:properties); r=jdm The bug is rust-lang/rust#10683 and there's no fix yet, plus it would take us a while to upgrade Rust anyway. Fixes #1258. Source-Repo: https://github.com/servo/servo Source-Revision: 148d1720e539c36ed44efdc7ebf3e45f25388f13 UltraBlame original commit: 28bc03c8fa39fea27af15f247cb7cc3c3f6fe31d
…unjunekim:cssissues); r=kmcallister Fixed this issue ( rust-lang/rust#10683 ) Source-Repo: https://github.com/servo/servo Source-Revision: c5d81f13c167ba46836b78359389e8d1a3f817d6 UltraBlame original commit: 19615f9ab014ee097b16427c1c85db9c1a353b6d
…S parse failure (from kmcallister:properties); r=jdm The bug is rust-lang/rust#10683 and there's no fix yet, plus it would take us a while to upgrade Rust anyway. Fixes #1258. Source-Repo: https://github.com/servo/servo Source-Revision: 148d1720e539c36ed44efdc7ebf3e45f25388f13 UltraBlame original commit: 28bc03c8fa39fea27af15f247cb7cc3c3f6fe31d
…unjunekim:cssissues); r=kmcallister Fixed this issue ( rust-lang/rust#10683 ) Source-Repo: https://github.com/servo/servo Source-Revision: c5d81f13c167ba46836b78359389e8d1a3f817d6 UltraBlame original commit: 19615f9ab014ee097b16427c1c85db9c1a353b6d
Fix false positive in `allow_attributes` This would emit a warning if used in a proc-macro with the feature `lint_reasons` enabled. This is now fixed. changelog: [`allow_attributes`]: Don't lint if in external macro
We have some code in Servo of the form:
The match will sometimes (nondeterministically) fail even though
name
matches one of the listed string literals. The bug apparently disappears if I change the code toSo I believe the
~str
returned byto_ascii_lower()
is getting freed before thematch
is done. (I couldn't reproduce the bug inside Valgrind, however.)You can see the actual Servo code here. It's a Mako template which outputs Rust code. If you build Servo you can see the generated code at
src/components/style/properties.rs
.We're using
so if you believe this bug is already fixed in
master
, let us know and we can upgrade.The text was updated successfully, but these errors were encountered: