This is an archive of the discontinued LLVM Phabricator instance.

[AST] Fix a clang crash on an invalid for-range statement.
ClosedPublic

Authored by hokein on Jun 8 2020, 5:54 AM.

Details

Summary

crash stack:

llvm-project/clang/lib/AST/ASTContext.cpp:2248: clang::TypeInfo clang::ASTContext::getTypeInfoImpl(const clang::Type *) const: Assertion `!A->getDeducedType().isNull() && "cannot request the size of an undeduced or dependent auto type"' failed.
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
 #0 0x00000000025bb0bf llvm::sys::PrintStackTrace(llvm::raw_ostream&) llvm-project/llvm/lib/Support/Unix/Signals.inc:564:13
 #1 0x00000000025b92b0 llvm::sys::RunSignalHandlers() llvm-project/llvm/lib/Support/Signals.cpp:69:18
 #2 0x00000000025bb535 SignalHandler(int) llvm-project/llvm/lib/Support/Unix/Signals.inc:396:3
 #3 0x00007f9ef9298110 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14110)
 #4 0x00007f9ef8d72761 raise /build/glibc-M65Gwz/glibc-2.30/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
 #5 0x00007f9ef8d5c55b abort /build/glibc-M65Gwz/glibc-2.30/stdlib/abort.c:81:7
 #6 0x00007f9ef8d5c42f get_sysdep_segment_value /build/glibc-M65Gwz/glibc-2.30/intl/loadmsgcat.c:509:8
 #7 0x00007f9ef8d5c42f _nl_load_domain /build/glibc-M65Gwz/glibc-2.30/intl/loadmsgcat.c:970:34
 #8 0x00007f9ef8d6b092 (/lib/x86_64-linux-gnu/libc.so.6+0x34092)
 #9 0x000000000458abe0 clang::ASTContext::getTypeInfoImpl(clang::Type const*) const llvm-project/clang/lib/AST/ASTContext.cpp:0:5

Diff Detail

Event Timeline

hokein created this revision.Jun 8 2020, 5:54 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 8 2020, 5:54 AM
hokein marked an inline comment as done.Jun 8 2020, 6:03 AM
hokein added inline comments.
clang/lib/Sema/SemaStmt.cpp
2437–2439

some details:
for the crash case, the RangeType is a Bar<int> class specialization, RequireCompleteType generates a definition decl of Bar<int>, which is invalid, and RequireCompleteType returns true, and doesn't emit a diagnostic (seems to suppress the "incomplete-type" diagnostic for invalid decls), so the trick InvalidateOnErrorScope (on Line 2396) doesn't invalidate the LoopVar Decl, we have to manually invalidate it.

sammccall accepted this revision.Jun 8 2020, 7:47 AM
sammccall added inline comments.
clang/test/SemaCXX/for-range-crash.cpp
7

What's the significance of the missing return type here? Can we add void)

Can we move this function out of the class?

(In both cases just to remove any confusion about what the problematic pattern actually is)

This revision is now accepted and ready to land.Jun 8 2020, 7:47 AM
hokein marked 2 inline comments as done.Jun 8 2020, 8:22 AM
hokein added inline comments.
clang/test/SemaCXX/for-range-crash.cpp
7

I tried both at the very beginning and failed, the crash needs both.

This revision was automatically updated to reflect the committed changes.
hokein marked an inline comment as done.