This is an archive of the discontinued LLVM Phabricator instance.

Verifier: accept enums as scopes
ClosedPublic

Authored by durin42 on Dec 8 2021, 8:15 AM.

Details

Summary

Rust allows enums to be scopes, as shown by the previous change. Sadly,
D111770 disallowed enums-as-scopes in the LLVM Verifier, which means
that LLVM HEAD stopped working for Rust compiles. As a result, we back
out the verifier part of D111770 with a modification to the testcase so
we don't break this in the future.

The testcase is now actual IR from rustc at commit 8f8092cc3, which is
the nightly as of 2021-09-28. I would expect rustc 1.57 to produce
similar or identical IR if someone wants to reproduce this IR in the
future with minimal changes. A recipe for reproducing the IR using rustc
is included in the test file.

Diff Detail

Event Timeline

durin42 created this revision.Dec 8 2021, 8:15 AM
durin42 requested review of this revision.Dec 8 2021, 8:15 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 8 2021, 8:15 AM
ychen added a comment.Dec 8 2021, 10:11 AM

Oops, apologies for breaking Rust. I'm no debuginfo expert, just wondering if we could keep this check for C/C++?

No worries on the break, it happens. I'm not familiar enough with how the validation works to know if there's a way to have C++-specific validations.

ychen added inline comments.Dec 8 2021, 10:58 AM
llvm/lib/IR/Verifier.cpp
888

This should work.

if (dwarf::isCPlusPlus(CurrentSourceLang)) {
  verifyODRTypeAsScopeOperand<DIType>(MD);
  verifyODRTypeAsScopeOperand<DILocalScope>(MD);
}

Oops, apologies for breaking Rust. I'm no debuginfo expert, just wondering if we could keep this check for C/C++?

Reckon it's worth the special case, though? I don't feel super strongly either way - I guess we already do have the "CurrentSourceLang" there and use it for some fortran special case, so we could test it here too. But I'm not sure how valuable it is?

The original bug/issue should be caught during IR merging instead - and since the goal is to support the case of member functions in enums, it's not like the LLVM codegen can't handle this case (when it's C++ or any other language).

(I assume the verifier check was added originally because members in enums broke LLVM in some way? But that bug has been/is being fixed so Rust keeps working? Or did it never break LLVM but instead just produce "weird" DWARF?)

ychen added a comment.Dec 9 2021, 1:26 PM

Oops, apologies for breaking Rust. I'm no debuginfo expert, just wondering if we could keep this check for C/C++?

Reckon it's worth the special case, though? I don't feel super strongly either way - I guess we already do have the "CurrentSourceLang" there and use it for some fortran special case, so we could test it here too. But I'm not sure how valuable it is?

The original bug/issue should be caught during IR merging instead - and since the goal is to support the case of member functions in enums, it's not like the LLVM codegen can't handle this case (when it's C++ or any other language).

(I assume the verifier check was added originally because members in enums broke LLVM in some way? But that bug has been/is being fixed so Rust keeps working? Or did it never break LLVM but instead just produce "weird" DWARF?)

It didn't break LLVM, just the debug IR does not make sense for C++. I was suggesting the "CurrentSourceLang" method so there is no need to think about if the issue may happen in any other way than IR merging. IMHO, it is valuable than losing a few lines of code. Since it is cheap enough to keep and maintain, I'd prefer to keep the check.

Oops, apologies for breaking Rust. I'm no debuginfo expert, just wondering if we could keep this check for C/C++?

Reckon it's worth the special case, though? I don't feel super strongly either way - I guess we already do have the "CurrentSourceLang" there and use it for some fortran special case, so we could test it here too. But I'm not sure how valuable it is?

The original bug/issue should be caught during IR merging instead - and since the goal is to support the case of member functions in enums, it's not like the LLVM codegen can't handle this case (when it's C++ or any other language).

(I assume the verifier check was added originally because members in enums broke LLVM in some way? But that bug has been/is being fixed so Rust keeps working? Or did it never break LLVM but instead just produce "weird" DWARF?)

It didn't break LLVM, just the debug IR does not make sense for C++. I was suggesting the "CurrentSourceLang" method so there is no need to think about if the issue may happen in any other way than IR merging. IMHO, it is valuable than losing a few lines of code. Since it is cheap enough to keep and maintain, I'd prefer to keep the check.

I guess the counterargument might be that there's probably lots of invariants for what constitutes valid/reasonable DWARF for C++ - but we don't comprehensively try to check for all those things, why would we check for this thing in particular?

Generally the IR verifier is more about: "If the IR is verified it won't crash LLVM/will produce valid DWARF"

ychen added a comment.Dec 9 2021, 2:42 PM

Oops, apologies for breaking Rust. I'm no debuginfo expert, just wondering if we could keep this check for C/C++?

Reckon it's worth the special case, though? I don't feel super strongly either way - I guess we already do have the "CurrentSourceLang" there and use it for some fortran special case, so we could test it here too. But I'm not sure how valuable it is?

The original bug/issue should be caught during IR merging instead - and since the goal is to support the case of member functions in enums, it's not like the LLVM codegen can't handle this case (when it's C++ or any other language).

(I assume the verifier check was added originally because members in enums broke LLVM in some way? But that bug has been/is being fixed so Rust keeps working? Or did it never break LLVM but instead just produce "weird" DWARF?)

It didn't break LLVM, just the debug IR does not make sense for C++. I was suggesting the "CurrentSourceLang" method so there is no need to think about if the issue may happen in any other way than IR merging. IMHO, it is valuable than losing a few lines of code. Since it is cheap enough to keep and maintain, I'd prefer to keep the check.

I guess the counterargument might be that there's probably lots of invariants for what constitutes valid/reasonable DWARF for C++ - but we don't comprehensively try to check for all those things, why would we check for this thing in particular?

Generally the IR verifier is more about: "If the IR is verified it won't crash LLVM/will produce valid DWARF"

Yeah, agreed that this is a rare special casing for C++, if it is preferred to be avoided, I think it makes sense to remove the check. Feel free to accept the patch assuming it looks good to you. Thanks for chiming in :-).

dblaikie accepted this revision.Dec 9 2021, 3:30 PM

Oops, apologies for breaking Rust. I'm no debuginfo expert, just wondering if we could keep this check for C/C++?

Reckon it's worth the special case, though? I don't feel super strongly either way - I guess we already do have the "CurrentSourceLang" there and use it for some fortran special case, so we could test it here too. But I'm not sure how valuable it is?

The original bug/issue should be caught during IR merging instead - and since the goal is to support the case of member functions in enums, it's not like the LLVM codegen can't handle this case (when it's C++ or any other language).

(I assume the verifier check was added originally because members in enums broke LLVM in some way? But that bug has been/is being fixed so Rust keeps working? Or did it never break LLVM but instead just produce "weird" DWARF?)

It didn't break LLVM, just the debug IR does not make sense for C++. I was suggesting the "CurrentSourceLang" method so there is no need to think about if the issue may happen in any other way than IR merging. IMHO, it is valuable than losing a few lines of code. Since it is cheap enough to keep and maintain, I'd prefer to keep the check.

I guess the counterargument might be that there's probably lots of invariants for what constitutes valid/reasonable DWARF for C++ - but we don't comprehensively try to check for all those things, why would we check for this thing in particular?

Generally the IR verifier is more about: "If the IR is verified it won't crash LLVM/will produce valid DWARF"

Yeah, agreed that this is a rare special casing for C++, if it is preferred to be avoided, I think it makes sense to remove the check. Feel free to accept the patch assuming it looks good to you. Thanks for chiming in :-).

Fair - I appreciate the discussion, but think I'll lean towards not including these checks.

This revision is now accepted and ready to land.Dec 9 2021, 3:30 PM

I don't have commit access, so could someone push this for me?

Thanks!

This revision was automatically updated to reflect the committed changes.
llvm/test/DebugInfo/dbg-rust-valid-enum-as-scope.ll