Skip to content

Miscompilation of rustc-produced IR since 01859da84bad95fd51d6a03b08b60c660e642a4f #58776

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

Closed
glandium opened this issue Nov 3, 2022 · 7 comments
Labels
llvm:optimizations miscompilation question A question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!

Comments

@glandium
Copy link
Contributor

glandium commented Nov 3, 2022

Compiling Firefox with cross language LTO + PGO (note: I haven't tried without PGO) produces a crashy Firefox on all platforms. I bisected this down to 01859da, and reverting that commit from current trunk fixes the issue.

Reproducer (sorry, it's massive, I haven't reduced it yet because I'm also in the middle of tracking down separate problems with non-trunk clang): https://drive.google.com/file/d/12s6DsTnMWIPuMikVRYTMPklyj-OeXH6f/view?usp=sharing
Instructions (run on x86-64 Linux):

  • Unpack testcase.tar.xz
  • cd testcase
  • run the command in the build file
  • run the command in the crash file (requires an X11 server ; without an X11, there's a different, unrelated crash)

In case this helps, this is a pernosco session with the crash: https://pernos.co/debug/Twdl8_V2QanMUEn2lEG0qg/index.html

Cc: @pcwalton, @nikic

@pcwalton
Copy link
Contributor

I'd like to make sure that this is a miscompilation (not saying it isn't!) and not UB that's now causing crashes. In particular if you write to immutable data behind an & reference and don't use UnsafeCell, that patch will probably cause your code to crash. (It could crash before, but it's especially likely to crash now.)

@nikic
Copy link
Contributor

nikic commented Mar 7, 2023

Does this issue still exist?

@glandium
Copy link
Contributor Author

glandium commented Mar 9, 2023

Does this issue still exist?

It does.

@xry111
Copy link
Contributor

xry111 commented Mar 31, 2023

Thunderbird suffers the same issue (with only LTO and no PGO). Disabling LTO hides the issue.

@nekopsykose
Copy link

the specific issue seems to fix itself if one disables the following optimisation:

diff --git a/llvm/lib/Analysis/BasicAliasAnalysis.cpp b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
index dc728c1cb..d476965b7 100644
--- a/llvm/lib/Analysis/BasicAliasAnalysis.cpp
+++ b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
@@ -704,12 +704,12 @@ ModRefInfo BasicAAResult::getModRefInfoMask(const MemoryLocation &Loc,
     //
     // An argument that is marked readonly and noalias is known to be
     // invariant while that function is executing.
-    if (const Argument *Arg = dyn_cast<Argument>(V)) {
-      if (Arg->hasNoAliasAttr() && Arg->onlyReadsMemory()) {
-        Result |= ModRefInfo::Ref;
-        continue;
-      }
-    }
+    // if (const Argument *Arg = dyn_cast<Argument>(V)) {
+    //   if (Arg->hasNoAliasAttr() && Arg->onlyReadsMemory()) {
+    //     Result |= ModRefInfo::Ref;
+    //     continue;
+    //   }
+    // }
 
     // A global constant can't be mutated.
     if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(V)) {

from the above changes only. sounds indeed like something broken on firefox side

pld-gitsync pushed a commit to pld-linux/llvm that referenced this issue May 4, 2023
keep fractional release until llvm/llvm-project#58776 is figured
@glandium
Copy link
Contributor Author

glandium commented May 5, 2023

Thank you for pinpointing the specific part that was causing problems. Along with rust compiler beta releases using LLVM 16 causing similar problems in a more reduced way, this allowed to pinpoint where the problem actually lies, and yes, it's something broken in Firefox unsafe code, but I'd argue because of the changes in 01859da it shouldn't allow the pattern that causes problems in the first place. I'll file a bug against the rust compiler.

Thanks again.

@glandium glandium closed this as completed May 5, 2023
@EugeneZelenko EugeneZelenko added the question A question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead! label May 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
llvm:optimizations miscompilation question A question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!
Projects
None yet
Development

No branches or pull requests

7 participants