[llvm] r265514 - [IRVerifier] Avoid crashing on an invalid compile unit.

Davide Italiano via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 6 13:19:43 PDT 2016


On Wed, Apr 6, 2016 at 8:25 AM, David Blaikie <dblaikie at gmail.com> wrote:
>
>
> On Tue, Apr 5, 2016 at 8:07 PM, Davide Italiano via llvm-commits
> <llvm-commits at lists.llvm.org> wrote:
>>
>> Author: davide
>> Date: Tue Apr  5 22:07:58 2016
>> New Revision: 265514
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=265514&view=rev
>> Log:
>> [IRVerifier] Avoid crashing on an invalid compile unit.
>>
>> Added:
>>     llvm/trunk/test/Verifier/dbg-invalid-compileunit.ll
>> Modified:
>>     llvm/trunk/lib/IR/Verifier.cpp
>>
>> Modified: llvm/trunk/lib/IR/Verifier.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Verifier.cpp?rev=265514&r1=265513&r2=265514&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/lib/IR/Verifier.cpp (original)
>> +++ llvm/trunk/lib/IR/Verifier.cpp Tue Apr  5 22:07:58 2016
>> @@ -4376,13 +4376,14 @@ void Verifier::verifyTypeRefs() {
>>    // Visit all the compile units again to map the type references.
>>    SmallDenseMap<const MDString *, const DIType *, 32> TypeRefs;
>>    for (auto *CU : CUs->operands())
>> -    if (auto Ts = cast<DICompileUnit>(CU)->getRetainedTypes())
>> -      for (DIType *Op : Ts)
>> -        if (auto *T = dyn_cast_or_null<DICompositeType>(Op))
>> -          if (auto *S = T->getRawIdentifier()) {
>> -            UnresolvedTypeRefs.erase(S);
>> -            TypeRefs.insert(std::make_pair(S, T));
>> -          }
>> +    if (isa<DICompileUnit>(CU))
>> +      if (auto Ts = cast<DICompileUnit>(CU)->getRetainedTypes())
>> +        for (DIType *Op : Ts)
>> +          if (auto *T = dyn_cast_or_null<DICompositeType>(Op))
>
>
> Total aside. I assume something should be checking that there aren't any
> null entries in the retained types list (or indeed any entries that aren't
> composite types, either)
>

Coming back to this, I wrote a synthetic testcase and we actually
crash in the Verifier.
I'll fix this later today. Thanks for noticing!

invalid retained type list
!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1,
producer: "clang version 3.0 (trunk 131941)", isOptimized: true,
runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes:
!1, subprograms: !3)
!1 = !DIFile(filename: "/d/j/debug-test.c", directory: "/Volumes/Data/b")
opt: /home/davide/work/llvm/include/llvm/Support/Casting.h:269:
typename llvm::cast_retty<X, Y*>::ret_type llvm::cast_or_null(Y*)
[with X = llvm::MDTuple; Y = llvm::Metadata; typename
llvm::cast_retty<X, Y*>::ret_type = llvm::MDTuple*]: Assertion
`isa<X>(Val) && "cast_or_null<Ty>() argument of incompatible type!"'
failed.
#0 0x0000000002887e7d llvm::sys::PrintStackTrace(llvm::raw_ostream&)
/home/davide/work/llvm/lib/Support/Unix/Signals.inc:322:0
#1 0x00000000028881fa PrintStackTraceSignalHandler(void*)
/home/davide/work/llvm/lib/Support/Unix/Signals.inc:380:0
#2 0x0000000002886958 llvm::sys::RunSignalHandlers()
/home/davide/work/llvm/lib/Support/Signals.cpp:44:0
#3 0x000000000288797c SignalHandler(int)
/home/davide/work/llvm/lib/Support/Unix/Signals.inc:210:0
#4 0x00007f91f73559f0 __restore_rt (/lib64/libpthread.so.0+0x109f0)
#5 0x00007f91f6507a98 __GI_raise (/lib64/libc.so.6+0x34a98)
#6 0x00007f91f650969a __GI_abort (/lib64/libc.so.6+0x3669a)
#7 0x00007f91f6500227 __assert_fail_base (/lib64/libc.so.6+0x2d227)
#8 0x00007f91f65002d2 (/lib64/libc.so.6+0x2d2d2)
#9 0x0000000001f0bab9 llvm::cast_retty<llvm::MDTuple,
llvm::Metadata*>::ret_type llvm::cast_or_null<llvm::MDTuple,
llvm::Metadata>(llvm::Metadata*)
/home/davide/work/llvm/include/llvm/Support/Casting.h:270:0
#10 0x0000000001f082f2 llvm::DICompileUnit::getRetainedTypes() const
/home/davide/work/llvm/include/llvm/IR/DebugInfoMetadata.h:1036:0
#11 0x00000000023b1ddd (anonymous
namespace)::Verifier::verifyTypeRefs()
/home/davide/work/llvm/lib/IR/Verifier.cpp:4382:0
#12 0x0000000002399355 (anonymous
namespace)::Verifier::verify(llvm::Module const&)
/home/davide/work/llvm/lib/IR/Verifier.cpp:313:0
#13 0x00000000023b2513 llvm::verifyModule(llvm::Module const&,
llvm::raw_ostream*) /home/davide/work/llvm/lib/IR/Verifier.cpp:4444:0
#14 0x0000000001118267 main /home/davide/work/llvm/tools/opt/opt.cpp:372:0
#15 0x00007f91f64f3580 __libc_start_main (/lib64/libc.so.6+0x20580)
#16 0x00000000010f3b59 _start
(/home/davide/work/build-llvm-Desktop-Default/bin/opt+0x10f3b59)
Stack dump:
0.    Program arguments:
/home/davide/work/build-llvm-Desktop-Default/./bin/opt -S -O3
FileCheck error: '-' is empty.

--
Davide

"There are no solved problems; there are only problems that are more
or less solved" -- Henri Poincare


More information about the llvm-commits mailing list