-
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
Malformed coverage data with a no_mangle
function
#117788
Comments
cc @Zalathar |
I was able to reproduce this on beta+nightly on my machine (macOS aarch64), so I should be able to dig into the mappings and see what LLVM is complaining about. (Thanks for the detailed report!) |
This seems to be where the |
When the error occurs in the above code, we have startLoc = (159, 59) and endLoc = (1, 4), causing the check to fail. That seems to correspond to this code: |
If I print out the raw values being read by
That NumLines value is 0xFFFFFF62, which is clearly bogus. Probably the result of integer overflow somewhere. |
Actually I've traced the bogus (1, 4) coordinates to the actual span processed by It looks like At this point I'm guessing the culprit is #116754. |
Hmm, but I can reproduce this on |
Manually bisected this down to |
After some more manual bisection, I'm pretty sure this started failing after #115507. That seems consistent with it being a latent coverage bug that has now been made more common by compiler-wide changes to spans. |
Even in prior revisions I can observe the spans created by |
(In this situation, |
This test isn't able to reproduce the malformed mappings that cause `llvm-cov` to fail, but does reproduce the underlying problem in a way that results in obviously incorrect mappings if the workaround is not present.
This test isn't able to reproduce the malformed mappings that cause `llvm-cov` to fail, but does reproduce the underlying problem in a way that results in obviously incorrect mappings if the workaround is not present.
Without the workaround applied, this test will produce malformed mappings that cause `llvm-cov` to fail. (And if it does emit well-formed mappings, they should be obviously incorrect.)
Without the workaround applied, this test will produce malformed mappings that cause `llvm-cov` to fail. (And if it does emit well-formed mappings, they should be obviously incorrect.)
Without the workaround applied, this test will produce malformed mappings that cause `llvm-cov` to fail. (And if it does emit well-formed mappings, they should be obviously incorrect.)
…vidtwco coverage: Avoid creating malformed macro name spans This is a workaround for rust-lang#117788. It detects a particular scenario where we would create malformed coverage spans that might cause `llvm-cov` to immediately exit with an error, preventing the user from processing coverage reports. The patch has been kept as simple as possible so that it's trivial to backport to beta (or stable) if desired. --- The `maybe_push_macro_name_span` method is trying to detect macro invocations, so that it can split a span into two parts just after the `!` of the invocation. Under some circumstances (probably involving nested macros), it gets confused and produces a span that is larger than the original span, and possibly extends outside its enclosing function and even into an adjacent file. In extreme cases, that can result in malformed coverage mappings that cause `llvm-cov` to fail. For now, we at least want to detect these egregious cases and avoid them, so that coverage reports can still be produced.
The fix for this has been cherry-picked into the upcoming stable release of 1.74, and has also been merged on nightly (1.76). It will probably still be broken in the initial version of the upcoming beta release (1.75); ideally the fix will also be be accepted on the beta branch at some point in the next 5 weeks. |
Without the workaround applied, this test will produce malformed mappings that cause `llvm-cov` to fail. (And if it does emit well-formed mappings, they should be obviously incorrect.)
Without the workaround applied, this test will produce malformed mappings that cause `llvm-cov` to fail. (And if it does emit well-formed mappings, they should be obviously incorrect.)
coverage: Be more strict about what counts as a "visible macro" This is a follow-up to the workaround in rust-lang#117827, and I believe it now properly fixes rust-lang#117788. The old code treats a span as having a “visible macro” if it is part of a macro-expansion, and its parent callsite's context is the same as the body span's context. But if the body span is itself part of an expansion, the macro in question might not actually be visible from the body span. That results in the macro name's length being meaningless as a span offset. We now only consider spans whose parent callsite is the same as the source callsite, i.e. the parent has no parent. --- I've also included some related cleanup for the code added by rust-lang#117827. That code was more complicated than normal, because I wanted it to be easy to backport to stable/beta.
Code
I tried to run
cargo llvm-cov
on this code:I expected the tool to work normally, but instead, this happened:
Please note this is the most minimal reproducible example I've been able to find.
Removing either the
no_mangle
attribute or theffi_panic_message
call does not reproduce the error, but theextern "C"
has not effect.I've tried to remove the
abi_stable
dependency but putting the required code in the same file or in a different crate (in the same workspace) does not reproduce the error.Associated
abi_stable
codeVersion it worked on
It most recently worked on: 1.73.0
Version with regression
rustc --version --verbose
:@rustbot modify labels: +regression-from-stable-to-beta -regression-untriaged
The text was updated successfully, but these errors were encountered: