Bug 117918 - UNO API: headers including themselves, causes IWYU assertion
Summary: UNO API: headers including themselves, causes IWYU assertion
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: framework (show other bugs)
Version:
(earliest affected)
6.2.0.0.alpha0+
Hardware: All All
: medium enhancement
Assignee: Miklos Vajna
URL:
Whiteboard: target:6.2.0
Keywords:
: 111081 (view as bug list)
Depends on:
Blocks: UNO
  Show dependency treegraph
 
Reported: 2018-05-30 21:26 UTC by Gabor Kelemen (allotropia)
Modified: 2018-09-16 19:01 UTC (History)
4 users (show)

See Also:
Crash report or crash signature:


Attachments
Diff between a fresh and a fixed up UnoApiHeadersTarget dir, showing problematic files (12.30 KB, patch)
2018-05-30 21:26 UTC, Gabor Kelemen (allotropia)
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Gabor Kelemen (allotropia) 2018-05-30 21:26:05 UTC
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:
  "com/sun/star/text/XTextRange.hpp" ->
  "com/sun/star/text/XTextRange.hpp"
/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:

#include "com/sun/star/text/XTextRange.hpp"

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.

I'm using:
include-what-you-use 0.9 based on clang version 5.0.1-2 (tags/RELEASE_501/final)
on Ubuntu 18.04.
Comment 1 Miklos Vajna 2018-06-01 09:30:49 UTC
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.)
Comment 2 Stephan Bergmann 2018-06-01 10:18:53 UTC
(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.
Comment 3 Commit Notification 2018-06-06 06:42:01 UTC
Miklos Vajna committed a patch related to this issue.
It has been pushed to "master":

http://cgit.freedesktop.org/libreoffice/core/commit/?id=a96a260a5fd6303eeebb26aee4be24ddf88391d1

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:
http://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 4 Gabor Kelemen (allotropia) 2018-07-03 18:03:04 UTC
*** Bug 111081 has been marked as a duplicate of this bug. ***