Re: Issue 982 in include-what-you-use: ipp files

1 view
Skip to first unread message

notifi...@include-what-you-use.org

unread,
Jan 10, 2022, 3:55:43 PM1/10/22
to include-wh...@googlegroups.com
Comment #21 on issue 982 by kimgr: ipp files
https://github.com/include-what-you-use/include-what-you-use/issues/982

Interesting... I don't think the Clang libraries do any threading behind the scenes (but I haven't followed Clang development closely for a while, so things could have changed).

I wonder if it's some kind of memory corruption issue; would be interesting to see the result with an ASAN-instrumented `include-what-you-use` binary. But I guess you're not building from source?

As for the original example you posted, I get very different behavior:
```
$ include-what-you-use --version
include-what-you-use 0.14 (git:aa7c663) based on clang version 10.0.0-4ubuntu1

$ include-what-you-use tests/982/a.cpp
In file included from tests/982/a.cpp:2:
In file included from tests/982/a.hpp:4:
In file included from tests/982/a_ipp.hpp:4:
/// ....
In file included from tests/982/a.hpp:4:
In file included from tests/982/a_ipp.hpp:4:
tests/982/a.hpp:4:10: error: #include nested too deeply
#include "a_ipp.hpp"
^
In file included from tests/982/a.cpp:2:
In file included from tests/982/a.hpp:4:
In file included from tests/982/a_ipp.hpp:4:
In file included from tests/982/a.hpp:4:
/// ...
In file included from tests/982/a_ipp.hpp:4:
In file included from tests/982/a.hpp:4:
tests/982/a_ipp.hpp:5:27: error: redefinition of 'Func1'
template<typename T> void Func1(T & t) { /*implementation */ }
^
tests/982/a_ipp.hpp:5:27: note: previous definition is here
template<typename T> void Func1(T & t) { /*implementation */ }
^
```
.. the preprocessor goes into a loop here until it gives up.

If I add include guards (`#pragma once`), it only complains that `a.hpp` doesn't need `a_ipp.hpp`, which can be worked around with a `// IWYU pragma: keep`.

So I wonder what's going on in your environment...


notifi...@include-what-you-use.org

unread,
Jan 10, 2022, 4:08:19 PM1/10/22
to include-wh...@googlegroups.com
OK, I was trying to build a mental model for how this works and why it fails. It's going slow, but I stumbled on this;
https://github.com/include-what-you-use/include-what-you-use/blob/master/iwyu.cc#L3668

Shortly after the line you cited, there's explicit processing to analyze associated headers before the main file. I suspect that's there to avoid the scenario you're running into. I wonder if it boils down to you having associated-header dependencies between headers/non-main files...

* When analyzing a.hpp, there's only one associated-dependency, between a.hpp and a_ipp.hpp
* When analyzing a_ipp.hpp, there's only one associated-dependency, between a.hpp and a_ipp.hpp
* When analyzing a.cpp, there's a graph of associated-dependencies: a.cpp => a.hpp => a_ipp.hpp, and analyzing the last two out of order seems to trigger this

This is just a hunch, and I'm not sure what to do about it yet. It seems to me it's not just a graph, it might be a cyclic graph, which makes it all the more complicated.

It would be nice if the order was a least consistent, but I'm not sure what the ordering should be. It feels intuitive to run in dependency order, but it's hard to sort in a consistent manner if there are cycles in the association chain.


Reply all
Reply to author
Forward
0 new messages