Am I missing something in this Value debug output code?

In the course of adding some new code I came across a debug output message before an assert that was extremely unhelpful. If I incorrectly try to delete a Value object that still has uses in a debug build, an debug message is printed just before an assertion that says it is telling me where the value is still being used but actually just tries to print the value itself multiple times, which in my case was crashing because the Value was already partially destructed.

It looked like a pretty simple and obvious fix and I was just going to go ahead and commit it, but when I looked at the revision history I saw that the current behavior has been in place since 2002. So I thought maybe it would be a good idea to get a reality check and make sure I wasn’t being an idiot in some way.

Can someone give me a second opinion?

Here’s the change I am proposing:

Index: lib/IR/Value.cpp

I think this just a bug.
I actually had the same bug in some other code.
Nowadays, i think this should just be “for (I : users())”

The main use of the use_begin/use_end idiom nowadays is to be able to modify the use list itself (IE people removing uses) without iterator invalidation.

I think Chandler changed the result of the operator* overload on use_iterator some time last year to produce a Use instead of a User. Both are implicitly convertible to Values, so this code compiles either way. It’s functionality isn’t actually covered by tests so… your fix looks correct. :slight_smile: