This is an archive of the discontinued LLVM Phabricator instance.

Apply -fdebug-prefix-map in reverse of command line order
AbandonedPublic

Authored by alxu on Jul 22 2018, 1:45 PM.

Details

Reviewers
probinson
Summary

Before this patch, it is applied in order of increasing OLD path length. This is not a useful behavior.

After this patch, it is applied based on the command line order from right to left, stopping on the first match.

Diff Detail

Event Timeline

alxu created this revision.Jul 22 2018, 1:45 PM
alxu added a comment.Jul 22 2018, 1:49 PM

Oh, I forgot to mention, this is the way that gcc does it. Therefore, I expect that almost everybody either doesn't care about the order, or assumes the gcc behavior.

probinson added a subscriber: probinson.

Needs a test.

Also, please document the option in clang/docs/UsersManual.rst. It should have been added when the option was first added, but certainly with right-to-left behavior it needs a mention. Nearly all options work left-to-right, so even though it's the same as gcc, not everybody comes to clang from gcc.

alxu planned changes to this revision.Jul 23 2018, 8:21 AM

The test syntax looked complicated, and I assumed that the documentation was terrible, like wine's, but it's actually pretty good, so I'll give it a go. I think the order is not really surprising though. It is run from right to left, but basically it means that right options override left options, which is how most of them work, e.g. -W and -Wno work based on the rightmost toggle, same with -f and -fno, etc.

alxu added a comment.Jul 23 2018, 8:23 AM

Also, is it right to use SmallVector in one place and vector in the other? I just assumed based on the surrounding declarations, but I really have no idea.

Re. SmallVector versus std::vector, they are functionally similar but have different memory-allocation behaviors. SmallVector includes a vector of N elements (where N is the template parameter) so does no dynamic allocation until you have more than N elements; but it takes up that much more space as a member of a class. It's mainly intended for stack variables. Given that this particular option is used rarely, I would probably go with std::vector. The code change otherwise is pretty simple and looks fine.

As for testing, it has its quirks for sure. But I'm happy to help sort out any issues. There should be plenty of CodeGen examples with debug info in the test tree to imitate. You'll want to start with C/C++ source and use -emit-llvm to get textual IR, then use FileCheck (our fancy-pants grep) to look for the new pathname patterns.

alxu added a comment.Jul 23 2018, 1:53 PM

I was just going to run llvm-dwarfdump.

I was just going to run llvm-dwarfdump.

Well, that's one of those quirks I mentioned. This is a Clang change, and Clang tests should exercise as little of LLVM as possible. That means you don't generate assembler or an object file, if you can possibly help it. And in this case, the path renaming should be visible in the debug-info metadata, which makes it easy enough to test by emitting LLVM IR and looking at that. It's by far the most common test idiom for changes to Clang's CodeGen layer.

Given that the prefix mapping happens in the LLVM IR, it should be no harder to emit IR and write a pattern-match than it would be for dwarfdump output. Really. Try clang -g -S -emit-llvm on some simple test file, then throw a remap option at it and see what's different.

alxu added a comment.Jul 23 2018, 3:05 PM

my general theory is that it's better to have tests that test everything at once if possible, but I guess it's unlikely enough that the debug info path will be correct in the IR and then not correct in the generated file and that that won't be caught by LLVM tests.

my general theory is that it's better to have tests that test everything at once if possible, but I guess it's unlikely enough that the debug info path will be correct in the IR and then not correct in the generated file and that that won't be caught by LLVM tests.

The in-tree lit tests are very focused unit tests. The principle here is that a more focused test will be easier to diagnose when it fails. The LLVM project on its own really does not have much end-to-end testing and hardly any of that looks at debug info. Instead we have a bunch of vendors all running their own test suites. It's very much a tradeoff, and I personally view the in-tree lit tests as barely more than basic smoke tests. But it's how the project works, and so new in-tree tests need to be consistent with that approach.

alxu abandoned this revision.Sep 7 2020, 10:04 AM