Issue 1140 in include-what-you-use: Assertion failed: Val && "isa<> used on a null pointer" on dependant template alias

1 view
Skip to first unread message

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

unread,
Nov 18, 2022, 8:30:21 AM11/18/22
to include-wh...@googlegroups.com
New issue 1140 by mous16: Assertion failed: Val && "isa<> used on a null pointer" on dependant template alias
https://github.com/include-what-you-use/include-what-you-use/issues/1140

include-what-you-use crashes when analyzing the following minum example.
```C++
template<int value, typename Type>
struct ClassValueType
{ };

template<int value>
struct ClassValue
{
template<typename Type>
using ClassType= ClassValueType<value, Type>;
};

template<template<typename> typename TemplateClassType>
struct FinalType
{
static void run() { TemplateClassType<int> instance{}; }
};

template<int value>
void test()
{
using Type= FinalType<ClassValue<value>::template ClassType>;
Type::run();
}

int main()
{
test<0>();
}
```
I've tried it on Windows, with a custom build of LLVM 15.0.5 and IWYU 0.19.

The analysis terminates with the following error:
```
test.cpp:22:55: (8, fwd decl) [ TemplateName ] ClassValue<value>::template ClassType
Assertion failed: Val && "isa<> used on a null pointer", file C:\Users\a00550533\AppData\Local\llvm\include\llvm/Support/Casting.h, line 109
```
[Here](https://github.com/include-what-you-use/include-what-you-use/files/10041558/iwyu_out.txt) you can find full IWYU output in verbose mode.

I cannot build IWYU nor LLVM in debug mode right now, but after some investigation I realized the assertion is emitted when reaching `iwyu.cc:1532`:
```C++
if (const auto* shadow_decl = dyn_cast<UsingShadowDecl>(used_decl)) {
```
I unfortunately have a really low understanding of LLVM APIs, but I found out that substituting `dyn_cast` with `dyn_cast_or_null` let IWYU avoid the assertion, and continue to the end of the analysis.

I'm really not able to say if this is a valid fix.




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

unread,
Nov 19, 2022, 12:05:56 PM11/19/22
to include-wh...@googlegroups.com
Comment #1 on issue 1140 by kimgr: Assertion failed: Val && "isa<> used on a null pointer" on dependant template alias
https://github.com/include-what-you-use/include-what-you-use/issues/1140

Thanks! It seems like a reasonable fix, but it might mask another problem -- I guess my main question is: why is `used_decl` null here?

Thanks for the self-contained repro, it should be possible to answer that question with that and some debug logging.


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

unread,
Nov 25, 2022, 4:19:07 PM11/25/22
to include-wh...@googlegroups.com
Comment #3 on issue 1140 by kimgr: Assertion failed: Val && "isa<> used on a null pointer" on dependant template alias
https://github.com/include-what-you-use/include-what-you-use/issues/1140

I couldn't come up with anything fancier than https://github.com/include-what-you-use/include-what-you-use/pull/1148. Let me know if that works for you.


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

unread,
Dec 4, 2022, 10:13:17 AM12/4/22
to include-wh...@googlegroups.com
Comment #4 on issue 1140 by kimgr: Assertion failed: Val && "isa<> used on a null pointer" on dependant template alias
https://github.com/include-what-you-use/include-what-you-use/issues/1140

Fixed as of https://github.com/include-what-you-use/include-what-you-use/commit/68646a5efd4d52aa615ddda1a7ff874b195a93df


Reply all
Reply to author
Forward
0 new messages