Created attachment 142423 [details]
Diff between a fresh and a fixed up UnoApiHeadersTarget dir, showing problematic files
While trying to help on bug #42949 I noticed that IWYU does not report unnecessary headers for some larger files with a lot of includes.
A bit of investigation revealed that IWYU fails in such situations with an assertion error, like this:
$ include-what-you-use -Wall -DBOOST_ERROR_CODE_HEADER_ONLY -DBOOST_SYSTEM_NO_DEPRECATED -DCPPU_ENV=gcc3 -DLINUX -DOSL_DEBUG_LEVEL=1 -DSAL_LOG_INFO -DSAL_LOG_WARN -DUNIX -DUNX -DX86_64 -D_PTHREADS -D_REENTRANT -DSD_DLLIMPLEMENTATION -DSDUI_DLL_NAME=\"libsduilo.so\" -DENABLE_SDREMOTE -DENABLE_SDREMOTE_BLUETOOTH -DLIBO_INTERNAL_ONLY -I/home/gabor/src/core/workdir/UnpackedTarball/icu/source -I/home/gabor/src/core/workdir/UnpackedTarball/icu/source/i18n -I/home/gabor/src/core/workdir/UnpackedTarball/icu/source/common -I/home/gabor/src/core/external/boost/include -I/home/gabor/src/core/workdir/UnpackedTarball/boost -I/home/gabor/src/core/external/bluez_bluetooth/inc -I/home/gabor/src/core/include -I/usr/lib/jvm/java-11-openjdk-amd64/include -I/usr/lib/jvm/java-11-openjdk-amd64/include/linux -I/home/gabor/src/core/config_host -I/home/gabor/src/core/sd/inc -I/home/gabor/src/core/sd/source/ui/inc -I/home/gabor/src/core/sd/source/ui/slidesorter/inc -I/home/gabor/src/core/workdir/SdiTarget/sd/sdi -I/home/gabor/src/core/workdir/CustomTarget/officecfg/registry -I/home/gabor/src/core/workdir/UnoApiHeadersTarget/udkapi/normal -I/home/gabor/src/core/workdir/UnoApiHeadersTarget/offapi/normal -I/home/gabor/src/core/workdir/UnpackedTarball/libxml2/include -isystem /usr/include/dbus-1.0 -isystem /usr/lib/x86_64-linux-gnu/dbus-1.0/include -isystem /usr/include/glib-2.0 -isystem /usr/lib/x86_64-linux-gnu/glib-2.0/include -finput-charset=UTF-8 -fmessage-length=0 -fno-common -pipe -fvisibility-inlines-hidden -fPIC -std=c++11 -c -x c++ /home/gabor/src/core/sd/inc/AnnotationEnumeration.hxx
Cycle in include-mapping:
/build/iwyu-mhPUyW/iwyu-5.0/iwyu_include_picker.cc:845: Assertion failed: Cycle in include-mapping
Looking at workdir/UnoApiHeadersTarget/offapi/normal/com/sun/star/text/XTextRange.hpp the problem is clear: it contains an include of itself:
Commenting this line out causes the assertion error to disappear. That is, until it hits a similar problem - so far, to get IWYU to run on sd/inc and chart2/inc needed commenting out 17 self includes.
I think it would be helpful to fix the underlying problem on the LO side and stop generating hpp files with includes to themselves.
That way IWYU and the find-unneeded-includes script could give relevant results about all the headers.
include-what-you-use 0.9 based on clang version 5.0.1-2 (tags/RELEASE_501/final)
on Ubuntu 18.04.
workdir/UnoApiHeadersTarget/offapi/normal/com/sun/star/text/XTextRange.hpp indeed includes itself.
I guess both sides could be improved: IWYU should not assert on valid C++ input, but it's indeed unnecessary that cppumaker emits code that like that.
Stephan, do you recall any reason for this, or it's just a matter of improving cppumaker? (I can look into that.)
(In reply to Miklos Vajna from comment #1)
> Stephan, do you recall any reason for this, or it's just a matter of
> improving cppumaker? (I can look into that.)
I very much assume the latter.
Miklos Vajna committed a patch related to this issue.
It has been pushed to "master":
tdf#117918 codemaker: avoid including ourselves in .hpp files
It will be available in 6.2.0.
The patch should be included in the daily builds available at
http://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
Affected users are encouraged to test the fix and report feedback.
*** Bug 111081 has been marked as a duplicate of this bug. ***