Re: Issue 951 in include-what-you-use: Bug: parsing /usr/lib/llvm-12/include/llvm/Support/Casting.h fails?

64 views
Skip to first unread message

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

unread,
Sep 20, 2021, 1:06:55 PM9/20/21
to include-wh...@googlegroups.com
Comment #1 on issue 951 by gabyx: Bug: parsing /usr/lib/llvm-12/include/llvm/Support/Casting.h fails?
https://github.com/include-what-you-use/include-what-you-use/issues/951

Would you know how to get this?, do you mean: to get a trace from the above `/usr/local/bin/cmake -E __run_co_compile --launcher=/usr/bin/ccache
--iwyu=/usr/local/bin/include-what-you-use ....`


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

unread,
Sep 20, 2021, 2:19:43 PM9/20/21
to include-wh...@googlegroups.com
Comment #2 on issue 951 by gabyx: Bug: parsing /usr/lib/llvm-12/include/llvm/Support/Casting.h fails?
https://github.com/include-what-you-use/include-what-you-use/issues/951

I got the include backtrace:

```
Error running '/usr/local/bin/include-what-you-use': . /cmake-general/tests/project/src/cli/Special.h
/cmake-general/tests/build/config/Version.h
/home/developer/.conan/data/fmt/8.0.1/_/_/package/6bdf91372b96de070e8534b0df31b9e6c83f8737/include/fmt/core.h
. /usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/cstdio
. /usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/cstring
.. /usr/include/string.h
... /usr/include/x86_64-linux-gnu/bits/libc-header-start.h
... /usr/lib/llvm-12/lib/clang/12.0.1/include/stddef.h
... /usr/include/strings.h
.... /usr/lib/llvm-12/lib/clang/12.0.1/include/stddef.h
. /usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/iterator
.. /usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/bits/stream_iterator.h
. /usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/limits
include-what-you-use: /usr/lib/llvm-12/include/llvm/Support/Casting.h:269: typename cast_retty<X, Y *>::ret_type llvm::cast(Y *) [X = clang::FunctionDecl, Y = const clang::NamedDecl]: Assertion `isa<X>(Val) && "cast<Ty>() argument of incompatible type!"' failed.
Subprocess aborted
```


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

unread,
Sep 20, 2021, 3:22:24 PM9/20/21
to include-wh...@googlegroups.com
Comment #4 on issue 951 by kimgr: Bug: parsing /usr/lib/llvm-12/include/llvm/Support/Casting.h fails?
https://github.com/include-what-you-use/include-what-you-use/issues/951

Sorry, I meant the backtrace/call stack from IWYU when it hits the assertion.
I think you should be able to invoke IWYU directly as follows:
```
$ cd /workspaces/cmake-general/tests/project/build/src/cli
$ /usr/local/bin/include-what-you-use -DFMT_SHARED
-I/workspaces/cmake-general/tests/project/src -I/workspaces/cmake-general/tests/project/build
-isystem
/home/developer/.conan/data/fmt/8.0.1/_/_/package/0dc4304bf2e1b43fb8919db1ac099bf93b4154ff/include -O3 -DNDEBUG
-stdlib=libstdc++ -fcolor-diagnostics -Wall -Wextra -Wshadow -Wnon-virtual-dtor
-Wold-style-cast -Wcast-align -Wunused -Woverloaded-virtual
-Wpedantic -Wconversion -Wsign-conversion -Wnull-dereference -Wdouble-promotion
-Wformat=2 -Werror -fsanitize=address -fsanitize=undefined,bounds
-fno-sanitize-recover=undefined,bounds -std=c++20 -Winvalid-pch -Xclang -include-pch -Xclang
/workspaces/cmake-general/tests/project/build/src/cli/CMakeFiles/cli.dir/cmake_pch.hxx.pch
-Xclang -include -Xclang /workspaces/cmake-general/tests/project/build/src/cli/CMakeFiles/cli.dir/cmake_pch.hxx -MD -MT
src/cli/CMakeFiles/cli.dir/main.cpp.o -MF CMakeFiles/cli.dir/main.cpp.o.d
-o CMakeFiles/cli.dir/main.cpp.o -c /workspaces/cmake-general/tests/project/src/cli/main.cpp
```
If you can iterate on that command until it runs into the same assertion, you should be able to run it through gdb to see a backtrace:
```
$ gdb -args /usr/local/bin/include-what-you-use -DFMT_SHARED ... rest of your cflags go here ...
```
The debugger should show from where the assertion is hit.


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

unread,
Sep 20, 2021, 3:23:28 PM9/20/21
to include-wh...@googlegroups.com
Comment #4 on issue 951 by kimgr: Bug: parsing /usr/lib/llvm-12/include/llvm/Support/Casting.h fails?
https://github.com/include-what-you-use/include-what-you-use/issues/951

Alternatively, if this is a public project, could you point me to it?


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

unread,
Sep 20, 2021, 3:28:34 PM9/20/21
to include-wh...@googlegroups.com
Comment #6 on issue 951 by gabyx: Bug: parsing /usr/lib/llvm-12/include/llvm/Support/Casting.h fails?
https://github.com/include-what-you-use/include-what-you-use/issues/951

Thanks! I test that!, Its not public so far. Maybe it becomes public we will see.


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

unread,
Sep 20, 2021, 3:31:49 PM9/20/21
to include-wh...@googlegroups.com
Comment #6 on issue 951 by gabyx: Bug: parsing /usr/lib/llvm-12/include/llvm/Support/Casting.h fails?
https://github.com/include-what-you-use/include-what-you-use/issues/951

Hurei I got the backtrace:

```
(gdb) run
Starting program: /usr/local/bin/include-what-you-use -H -DFMT_SHARED -I/cmake-general/tests/project/src -I/cmake-general/tests/build -isystem /home/developer/.conan/data/fmt/8.0.1/_/_/package/6bdf91372b96de070e8534b0df31b9e6c83f8737/include -g -stdlib=libstdc++ -fcolor-diagnostics -Wall -Wextra -Wshadow -Wnon-virtual-dtor -Wold-style-cast -Wcast-align -Wunused -Woverloaded-virtual -Wpedantic -Wconversion -Wsign-conversion -Wnull-dereference -Wdouble-promotion -Wformat=2 -Werror -fsanitize=address -fsanitize=undefined,bounds -fno-sanitize-recover=undefined,bounds -std=c++20 -Winvalid-pch -Xclang -include-pch -Xclang /cmake-general/tests/build/src/cli/CMakeFiles/cli.dir/cmake_pch.hxx.pch -Xclang -include -Xclang /cmake-general/tests/build/src/cli/CMakeFiles/cli.dir/cmake_pch.hxx -MD -MT src/cli/CMakeFiles/cli.dir/main.cpp.o -MF CMakeFiles/cli.dir/main.cpp.o.d -o CMakeFiles/cli.dir/main.cpp.o -c /cmake-general/tests/project/src/cli/main.cpp
warning: Error disabling address space randomization: Operation not permitted
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
/cmake-general/tests/project/src/cli/Special.h
/cmake-general/tests/build/config/Version.h
/home/developer/.conan/data/fmt/8.0.1/_/_/package/6bdf91372b96de070e8534b0df31b9e6c83f8737/include/fmt/core.h
. /usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/cstdio
. /usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/cstring
.. /usr/include/string.h
... /usr/include/x86_64-linux-gnu/bits/libc-header-start.h
... /usr/lib/llvm-12/lib/clang/12.0.1/include/stddef.h
... /usr/include/strings.h
.... /usr/lib/llvm-12/lib/clang/12.0.1/include/stddef.h
. /usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/iterator
.. /usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/bits/stream_iterator.h
. /usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/limits
include-what-you-use: /usr/lib/llvm-12/include/llvm/Support/Casting.h:269: typename cast_retty<X, Y *>::ret_type llvm::cast(Y *) [X = clang::FunctionDecl, Y = const clang::NamedDecl]: Assertion `isa<X>(Val) && "cast<Ty>() argument of incompatible type!"' failed.

Program received signal SIGABRT, Aborted.
__GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:49
49 ../sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) backtrace
#0 __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:49
#1 0x00007f18e5356864 in __GI_abort () at abort.c:79
#2 0x00007f18e5356749 in __assert_fail_base (fmt=0x7f18e54dff78 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n",
assertion=0x82d785 "isa<X>(Val) && \"cast<Ty>() argument of incompatible type!\"",
file=0x82d67c "/usr/lib/llvm-12/include/llvm/Support/Casting.h", line=269, function=<optimized out>) at assert.c:92
#3 0x00007f18e53683d6 in __GI___assert_fail (assertion=0x82d785 "isa<X>(Val) && \"cast<Ty>() argument of incompatible type!\"",
file=0x82d67c "/usr/lib/llvm-12/include/llvm/Support/Casting.h", line=269,
function=0x843c98 "typename cast_retty<X, Y *>::ret_type llvm::cast(Y *) [X = clang::FunctionDecl, Y = const clang::NamedDecl]")
at assert.c:101
#4 0x00000000005deb38 in llvm::cast_retty<clang::FunctionDecl, clang::NamedDecl const*>::ret_type llvm::cast<clang::FunctionDecl, clang::NamedDecl const>(clang::NamedDecl const*) ()
#5 0x00000000005f5bb8 in include_what_you_use::IwyuBaseAstVisitor<include_what_you_use::IwyuAstConsumer>::VisitCastExpr(clang::CastExpr*)
()
#6 0x00000000005f5ae5 in clang::RecursiveASTVisitor<include_what_you_use::IwyuAstConsumer>::WalkUpFromCastExpr(clang::CastExpr*) ()
#7 0x0000000000474861 in clang::RecursiveASTVisitor<include_what_you_use::IwyuAstConsumer>::WalkUpFromImplicitCastExpr(clang::ImplicitCastExpr*) ()
#8 0x0000000000474684 in clang::RecursiveASTVisitor<include_what_you_use::IwyuAstConsumer>::TraverseImplicitCastExpr(clang::ImplicitCastExpr*, llvm::SmallVectorImpl<llvm::PointerIntPair<clang::Stmt*, 1u, bool, llvm::PointerLikeTypeTraits<clang::Stmt*>, llvm::PointerIntPairInfo<clang::Stmt*, 1u, llvm::PointerLikeTypeTraits<clang::Stmt*> > > >*) ()
#9 0x00000000004561a3 in clang::RecursiveASTVisitor<include_what_you_use::IwyuAstConsumer>::dataTraverseNode(clang::Stmt*, llvm::SmallVectorImpl<llvm::PointerIntPair<clang::Stmt*, 1u, bool, llvm::PointerLikeTypeTraits<clang::Stmt*>, llvm::PointerIntPairInfo<clang::Stmt*, 1u, llvm::PointerLikeTypeTraits<clang::Stmt*> > > >*) ()
#10 0x000000000044c628 in clang::RecursiveASTVisitor<include_what_you_use::IwyuAstConsumer>::TraverseStmt(clang::Stmt*, llvm::SmallVectorImpl<llvm::PointerIntPair<clang::Stmt*, 1u, bool, llvm::PointerLikeTypeTraits<clang::Stmt*>, llvm::PointerIntPairInfo<clang::Stmt*, 1u, llvm::PointerLikeTypeTraits<clang::Stmt*> > > >*) ()
--Type <RET> for more, q to quit, c to continue without paging-- c
#11 0x000000000044c2ed in include_what_you_use::BaseAstVisitor<include_what_you_use::IwyuAstConsumer>::TraverseStmt(clang::Stmt*) ()
#12 0x00000000004715a0 in clang::RecursiveASTVisitor<include_what_you_use::IwyuAstConsumer>::TraverseCallExpr(clang::CallExpr*, llvm::SmallVectorImpl<llvm::PointerIntPair<clang::Stmt*, 1u, bool, llvm::PointerLikeTypeTraits<clang::Stmt*>, llvm::PointerIntPairInfo<clang::Stmt*, 1u, llvm::PointerLikeTypeTraits<clang::Stmt*> > > >*) ()
#13 0x0000000000471685 in include_what_you_use::BaseAstVisitor<include_what_you_use::IwyuAstConsumer>::TraverseCallExpr(clang::CallExpr*) ()
#14 0x0000000000455fb9 in clang::RecursiveASTVisitor<include_what_you_use::IwyuAstConsumer>::dataTraverseNode(clang::Stmt*, llvm::SmallVectorImpl<llvm::PointerIntPair<clang::Stmt*, 1u, bool, llvm::PointerLikeTypeTraits<clang::Stmt*>, llvm::PointerIntPairInfo<clang::Stmt*, 1u, llvm::PointerLikeTypeTraits<clang::Stmt*> > > >*) ()
#15 0x000000000044c628 in clang::RecursiveASTVisitor<include_what_you_use::IwyuAstConsumer>::TraverseStmt(clang::Stmt*, llvm::SmallVectorImpl<llvm::PointerIntPair<clang::Stmt*, 1u, bool, llvm::PointerLikeTypeTraits<clang::Stmt*>, llvm::PointerIntPairInfo<clang::Stmt*, 1u, llvm::PointerLikeTypeTraits<clang::Stmt*> > > >*) ()
#16 0x000000000044c2ed in include_what_you_use::BaseAstVisitor<include_what_you_use::IwyuAstConsumer>::TraverseStmt(clang::Stmt*) ()
#17 0x0000000000458f10 in clang::RecursiveASTVisitor<include_what_you_use::IwyuAstConsumer>::TraverseCompoundStmt(clang::CompoundStmt*, llvm::SmallVectorImpl<llvm::PointerIntPair<clang::Stmt*, 1u, bool, llvm::PointerLikeTypeTraits<clang::Stmt*>, llvm::PointerIntPairInfo<clang::Stmt*, 1u, llvm::PointerLikeTypeTraits<clang::Stmt*> > > >*) ()
#18 0x0000000000454fdd in clang::RecursiveASTVisitor<include_what_you_use::IwyuAstConsumer>::dataTraverseNode(clang::Stmt*, llvm::SmallVectorImpl<llvm::PointerIntPair<clang::Stmt*, 1u, bool, llvm::PointerLikeTypeTraits<clang::Stmt*>, llvm::PointerIntPairInfo<clang::Stmt*, 1u, llvm::PointerLikeTypeTraits<clang::Stmt*> > > >*) ()
#19 0x000000000044c628 in clang::RecursiveASTVisitor<include_what_you_use::IwyuAstConsumer>::TraverseStmt(clang::Stmt*, llvm::SmallVectorImpl<llvm::PointerIntPair<clang::Stmt*, 1u, bool, llvm::PointerLikeTypeTraits<clang::Stmt*>, llvm::PointerIntPairInfo<clang::Stmt*, 1u, llvm::PointerLikeTypeTraits<clang::Stmt*> > > >*) ()
#20 0x000000000044c2ed in include_what_you_use::BaseAstVisitor<include_what_you_use::IwyuAstConsumer>::TraverseStmt(clang::Stmt*) ()
#21 0x00000000006205b7 in clang::RecursiveASTVisitor<include_what_you_use::IwyuAstConsumer>::TraverseFunctionHelper(clang::FunctionDecl*) ()
#22 0x000000000042bfc3 in clang::RecursiveASTVisitor<include_what_you_use::IwyuAstConsumer>::TraverseFunctionDecl(clang::FunctionDecl*) ()
#23 0x0000000000423b57 in clang::RecursiveASTVisitor<include_what_you_use::IwyuAstConsumer>::TraverseDecl(clang::Decl*) ()
#24 0x000000000041fda9 in include_what_you_use::BaseAstVisitor<include_what_you_use::IwyuAstConsumer>::TraverseDecl(clang::Decl*) ()
#25 0x00000000004308ec in clang::RecursiveASTVisitor<include_what_you_use::IwyuAstConsumer>::TraverseDeclContextHelper(clang::DeclContext*) ()
#26 0x0000000000430621 in clang::RecursiveASTVisitor<include_what_you_use::IwyuAstConsumer>::TraverseTranslationUnitDecl(clang::TranslationUnitDecl*) ()
#27 0x00000000004240d9 in clang::RecursiveASTVisitor<include_what_you_use::IwyuAstConsumer>::TraverseDecl(clang::Decl*) ()
#28 0x000000000041fda9 in include_what_you_use::BaseAstVisitor<include_what_you_use::IwyuAstConsumer>::TraverseDecl(clang::Decl*) ()
#29 0x0000000000411291 in include_what_you_use::IwyuAstConsumer::HandleTranslationUnit(clang::ASTContext&) ()
#30 0x00007f18eb9d5b74 in clang::ParseAST(clang::Sema&, bool, bool) () from /usr/lib/llvm-12/lib/libclang-cpp.so.12
#31 0x00007f18ecf6ee18 in clang::FrontendAction::Execute() () from /usr/lib/llvm-12/lib/libclang-cpp.so.12
#32 0x00007f18ecefc8a1 in clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) () from /usr/lib/llvm-12/lib/libclang-cpp.so.12
#33 0x000000000040d81c in main ()
```


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

unread,
Sep 20, 2021, 3:53:14 PM9/20/21
to include-wh...@googlegroups.com
Comment #7 on issue 951 by kimgr: Bug: parsing /usr/lib/llvm-12/include/llvm/Support/Casting.h fails?
https://github.com/include-what-you-use/include-what-you-use/issues/951

Cool, thanks!

So the failing line is https://github.com/include-what-you-use/include-what-you-use/blob/master/iwyu.cc#L1906. I wonder what that `NamedDecl` is if it isn't a function... Do you get any relevant context if you up IWYU's verbosity level? Add `-Xiwyu -v6` to the command line, and it should dump the AST as it traverses, all the way up to the assertion.


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

unread,
Sep 21, 2021, 1:49:48 AM9/21/21
to include-wh...@googlegroups.com
Comment #9 on issue 951 by captaincrutches: Bug: parsing /usr/lib/llvm-12/include/llvm/Support/Casting.h fails?
https://github.com/include-what-you-use/include-what-you-use/issues/951

Throwing my hat in to say I'm encountering this issue as well, in particular it's present when a file includes from the [fmt](https://github.com/fmtlib/fmt) library (as appears to be the case in @gabyx's trace above).

I've come up with a minimal reproducible case:

```fmtbug.cpp
#include <fmt/core.h>

#include <iostream>
#include <string>

int main()
{
std::string str = fmt::format("IWYU fails {}", "here");
std::cout << str << std::endl;
}
```

No cmake needed, just run `include-what-you-use -std=c++20 fmtbug.cpp` (if the above code is `fmtbug.cpp` and fmt is in your include path) and I experience the error on IWYU 0.16 (llvm 12) with fmt 8.0.1.

Perhaps noteworthy is this started happening when fmt updated to 8.x; it didn't happen on fmt 7.x.

Hope that helps!


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

unread,
Sep 21, 2021, 11:58:25 AM9/21/21
to include-wh...@googlegroups.com
Edit to add the output on that code with `-v6`: [iwyu_fmt.txt](https://github.com/include-what-you-use/include-what-you-use/files/7204572/iwyu_fmt.txt)



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

unread,
Sep 21, 2021, 3:55:50 PM9/21/21
to include-wh...@googlegroups.com
Comment #9 on issue 951 by kimgr: Bug: parsing /usr/lib/llvm-12/include/llvm/Support/Casting.h fails?
https://github.com/include-what-you-use/include-what-you-use/issues/951

This looks more curious than I expected at first sight :-).

I added logging in `VisitCastExpr` to print the decl-kind:
```diff
diff --git a/iwyu.cc b/iwyu.cc
index 6e6a766..f4dd388 100644
--- a/iwyu.cc
+++ b/iwyu.cc
@@ -1902,6 +1902,8 @@ class IwyuBaseAstVisitor : public BaseAstVisitor<Derived> {
// its return type so we can see through up/down-casts via such conversions.
const Type* converted_from_type = nullptr;
if (const NamedDecl* conv_decl = expr->getConversionFunction()) {
+ VERRS(1) << "CONVFUNC: ptr=" << (void*)conv_decl
+ << ", declkind=" << string(conv_decl->getDeclKindName()) << "\n";
converted_from_type =
cast<FunctionDecl>(conv_decl)->getReturnType().getTypePtr();
}
```
and the result is:
```
CONVFUNC: ptr=0x6310004a9500, declkind=CXXConversion
CONVFUNC: ptr=0x6310006c1230, declkind=CXXConstructor
CONVFUNC: ptr=0x6310005833e8, declkind=AccessSpec
include-what-you-use: /usr/lib/llvm-13/include/llvm/Support/Casting.h:269: typename cast_retty<X, Y *>::ret_type llvm::cast(Y *) [X = clang::FunctionDecl, Y = const clang::NamedDecl]: Assertion `isa<X>(Val) && "cast<Ty>() argument of incompatible type!"' failed.
Aborted (core dumped)
```
Hmm. `AccessSpecDecl`? That "decl" represents the `private:`/`public:`/`protected:` access specifiers. Doesn't seem very likely to be a valid conversion function... `AccessSpecDecl` also maps to enum value `0` in Clang's `DeclKind`, so we're probably looking at a spurious zero value somewhere.

I built IWYU with ubsan:
```
$ cmake -G Ninja -DCMAKE_PREFIX_PATH=/usr/lib/llvm-13 -DCMAKE_CXX_COMPILER=clang++-13 -DCMAKE_CXX_FLAGS=-fsanitize=undefined ../../include-what-you-use
```
and it reports:
```
$ include-what-you-use -std=c++20 -I ~/code/fmt/include/ t.cc
/usr/lib/llvm-13/include/clang/AST/Decl.h:2812:62: runtime error: member call on address 0x6310005833e8 which does not point to an object of type 'clang::Decl'
0x6310005833e8: note: object has invalid vptr
10 63 00 00 6e 00 08 00 e3 00 00 00 a0 80 4a 00 10 63 00 00 80 a7 4c 00 10 63 00 00 00 00 00 00
^~~~~~~~~~~~~~~~~~~~~~~
invalid vptr
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /usr/lib/llvm-13/include/clang/AST/Decl.h:2812:62 in
/usr/lib/llvm-13/include/clang/AST/DeclBase.h:433:51: runtime error: member access within address 0x6310005833e8 which does not point to an object of type 'const clang::Decl'
0x6310005833e8: note: object has invalid vptr
10 63 00 00 6e 00 08 00 e3 00 00 00 a0 80 4a 00 10 63 00 00 80 a7 4c 00 10 63 00 00 00 00 00 00
^~~~~~~~~~~~~~~~~~~~~~~
invalid vptr
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /usr/lib/llvm-13/include/clang/AST/DeclBase.h:433:51 in
include-what-you-use: /usr/lib/llvm-13/include/llvm/Support/Casting.h:269: typename cast_retty<X, Y *>::ret_type llvm::cast(Y *) [X = clang::FunctionDecl, Y = const clang::NamedDecl]: Assertion `isa<X>(Val) && "
cast<Ty>() argument of incompatible type!"' failed.
Aborted (core dumped)
```

I'm not really sure what to make of that. I suspected memory corruption, built with ASAN, but got no complaints.


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

unread,
Sep 21, 2021, 10:06:28 PM9/21/21
to include-wh...@googlegroups.com
Comment #10 on issue 951 by captaincrutches: Bug: parsing /usr/lib/llvm-12/include/llvm/Support/Casting.h fails?
https://github.com/include-what-you-use/include-what-you-use/issues/951

Interestingly, if I build LLVM (13.0.0-rc3) locally (rather than using the 12.0.1 installed through my package manager), then IWYU (latest master) against that, and apply your change, I only get the first two of those log lines, then the exception before it reaches the third. And I don't get the ubsan messages either.

For me, it seems the call to `expr->getConversionFunction()` is failing, and [this cast](https://github.com/llvm/llvm-project/blob/f6b09e394a5fad4b33f8746195377f4f638e2c8d/clang/lib/AST/Expr.cpp#L1942) is the culprit - at least, that's what the backtrace tells me:
```
#0 0x00007ffff7a2720e in raise () from /lib64/libc.so.6
#1 0x00007ffff7a11536 in abort () from /lib64/libc.so.6
#2 0x00007ffff7a1141f in __assert_fail_base.cold () from /lib64/libc.so.6
#3 0x00007ffff7a1ff12 in __assert_fail () from /lib64/libc.so.6
#4 0x0000000001b6a454 in llvm::cast<clang::CXXConstructExpr, clang::Expr const> (Val=0x7ffff73ab2f8) at /home/captaincrutches/Projects/llvm-project/llvm/include/llvm/Support/Casting.h:269
#5 0x0000000001bee7a5 in clang::CastExpr::getConversionFunction (this=0x7ffff73ab358) at /home/captaincrutches/Projects/llvm-project/clang/lib/AST/Expr.cpp:1942
#6 0x0000000000b0ed4d in include_what_you_use::IwyuBaseAstVisitor<include_what_you_use::IwyuAstConsumer>::VisitCastExpr(clang::CastExpr*) ()
```

I couldn't tell you why, as I'm not nearly familiar enough with IWYU/LLVM's code to have a reasonable idea what's going on, but I'm happy to provide any other info I can if it'd help debug this - I use fmt extensively in my projects, and would very much like to have IWYU play nicely with it.


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

unread,
Sep 22, 2021, 1:22:04 AM9/22/21
to include-wh...@googlegroups.com
Comment #11 on issue 951 by kimgr: Bug: parsing /usr/lib/llvm-12/include/llvm/Support/Casting.h fails?
https://github.com/include-what-you-use/include-what-you-use/issues/951

Interesting. If you can build LLVM/Clang with relative ease (it always takes me hours due to limited hardware), could you build it with `-fsanitize=address,undefined` and IWYU likewise? Feels like there must be some kind of memory error causing this, and ASAN should be able to catch it.


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

unread,
Sep 22, 2021, 2:54:37 PM9/22/21
to include-wh...@googlegroups.com
Comment #12 on issue 951 by kimgr: Bug: parsing /usr/lib/llvm-12/include/llvm/Support/Casting.h fails?
https://github.com/include-what-you-use/include-what-you-use/issues/951

I managed to build a stand-alone project that reproduces this, so I think it might be a Clang bug. I'll see if I can package it up and ask around in the Clang community. `fmt` could be doing something funny, but it should never crash the compiler.


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

unread,
Sep 22, 2021, 4:04:08 PM9/22/21
to include-wh...@googlegroups.com
Comment #13 on issue 951 by gabyx: Bug: parsing /usr/lib/llvm-12/include/llvm/Support/Casting.h fails?
https://github.com/include-what-you-use/include-what-you-use/issues/951

That would be great =)


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

unread,
Sep 22, 2021, 4:05:16 PM9/22/21
to include-wh...@googlegroups.com
Comment #14 on issue 951 by gabyx: Bug: parsing /usr/lib/llvm-12/include/llvm/Support/Casting.h fails?
https://github.com/include-what-you-use/include-what-you-use/issues/951

That would be great =), The thing is it does not crash the compiler when compiled with clang++, ok of course IWYU is using some other parts of that tool chain i guess... AST etc...


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

unread,
Sep 22, 2021, 4:15:04 PM9/22/21
to include-wh...@googlegroups.com
Comment #15 on issue 951 by kimgr: Bug: parsing /usr/lib/llvm-12/include/llvm/Support/Casting.h fails?
https://github.com/include-what-you-use/include-what-you-use/issues/951

The only place the compiler calls `getConversionFunction` is here: https://github.com/llvm/llvm-project/blob/main/clang/lib/Sema/SemaExpr.cpp#L9751, and it appears the result is only used for locations in error reporting. So I suspect the worst that could happen is that an error message points to the wrong place.


Reply all
Reply to author
Forward
0 new messages