This is an archive of the discontinued LLVM Phabricator instance.

[Verifier] Check that debug values have proper size
ClosedPublic

Authored by loladiro on Nov 2 2015, 7:32 PM.

Details

Summary

Teach the Verifier to make sure that the storage size given to llvm.dbg.declare or the value size given to llvm.dbg.value agree with what is declared in DebugInfo. This is implicitly assumed in a number of passes (e.g. in SROA). Additionally this catches a number of common mistakes, such as passing a pointer when a value was intended or vice versa.

One complication comes from stack coloring which modifies the original IR when in merges allocas in order to make sure that if AA falls back to the IR it gets the correct result. However, given this new invariant, indiscriminately replacing one alloca by a different (differently sized one) is no longer valid. My proposed fix is to just undef out any use of the alloca in a dbg.declare in this case.

Additionally, I had to fix a number of test cases. Of particular note:

  • I regenerated dbg-changes-codegen-branch-folding.ll from the given source as it was affected by the bug fixed in D14186
  • two-cus-from-same-file.ll was changed to avoid having a variable-typed debug variable as that would depend on the target, even though this test is supposed to be generic
  • I had to manually declared size/align for reference types (c.f. D14275)
  • fpstack-debuginstr-kill.ll required changing double to long double
  • most others were just a question of adding OP_deref

Diff Detail

Repository
rL LLVM

Event Timeline

loladiro updated this revision to Diff 39027.Nov 2 2015, 7:32 PM
loladiro retitled this revision from to [Verifier] Check that debug values have proper size.
loladiro updated this object.
loladiro added a reviewer: aprantl.
loladiro set the repository for this revision to rL LLVM.
loladiro added a subscriber: hfinkel.

Also note that these are just the X86/Generic tests. I'm now building a copy of LLVM that includes all backends to fix any other tests that might be backend specific, but wanted to get the review started.

loladiro updated this revision to Diff 39029.Nov 2 2015, 8:16 PM

Fix tests for other architectures (much less bad than expected, only 3)

loladiro updated this revision to Diff 43294.Dec 18 2015, 7:39 PM

Rebased. Now that both dependencies have landed, this can be committed.

loladiro updated this revision to Diff 44169.Jan 6 2016, 3:06 PM

Rebased. @aprantl Does this look good now?

aprantl accepted this revision.Jan 7 2016, 1:00 PM
aprantl edited edge metadata.

Looks generable reasonable to me. LGTM with inline comments addressed.

lib/IR/Verifier.cpp
425–426

verifyDIExpression for consistency?

3881

If the first operator is an is an Op_deref, we could theoretically ensure that it is at least pointer-sized.

test/CodeGen/X86/misched-code-difference-with-debug.ll
90

Are these all cases where the deref was legitimately missing or are you adding it to disable the verification?

test/DebugInfo/Generic/two-cus-from-same-file.ll
27–28

?

This revision is now accepted and ready to land.Jan 7 2016, 1:00 PM
loladiro added inline comments.Jan 7 2016, 1:14 PM
lib/IR/Verifier.cpp
425–426

Sounds reasonable.

3881

Yep, sounds reasonable (I realized the same looking at your other comment). Will do. Should we actually require it's a pointer or just pointer-sized?

test/CodeGen/X86/misched-code-difference-with-debug.ll
90

The second two were legitimately missing, but I think I made a mistake, because !29 is also used for the first one on !19. Coincidentally, that suggests another check for the verifier: If there's a DW_OP_deref in the expression, the value needs to be a pointer. Will fix and also add that check.

test/DebugInfo/Generic/two-cus-from-same-file.ll
27–28

The debug info used to describe pointers as 32bit, but this is in Generic/ so should have a dependency on the pointer size.

loladiro updated this revision to Diff 44254.Jan 7 2016, 1:47 PM
loladiro edited edge metadata.

Remove incorrectly added deref from one test and add another verifier check
to make sure llvm.dbg.value calls with DW_OP_deref as the first element of
the expression are only called with pointer-sized values.

This revision was automatically updated to reflect the committed changes.