[cfe-dev] Fix segfault on sizeof(incomplete type)

Martin Doucha next_ghost at quick.cz
Sat Aug 9 14:06:07 PDT 2008


Hi,
I've reported a segfault before in ASTRecordLayout::LayoutField(). 
There's a NULL pointer dereference if clang tries to calculate size of 
struct which contains incomplete type (eg. another struct which is 
declared but not defined). This patch should fix the problem and let 
clang abort on the appropriate assert instead.

BTW, some of the asserts in ASTContext::getTypeInfo() could be turned 
into simple compile errors because C99 forbids using sizeof operator on 
incomplete types.

When you apply this patch, you can close bug 2400. My problem will be 
fixed and the problem reported by Mr. Lopes is invalid (size_t is 
defined in <stddef.h> so its use in typedef on line 1 of the test case 
is not allowed without #include <stddef.h>).

Regards,
Martin Doucha
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: incomplete.patch
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20080809/d4ced8d6/attachment.ksh>


More information about the cfe-dev mailing list