[cfe-commits] [patch] (Was: Assertion failure on invalid code.)

Enea Zaffanella zaffanella at cs.unipr.it
Tue Jan 8 05:26:53 PST 2013


On 01/06/2013 06:49 PM, Enea Zaffanella wrote:
> Hello.
>
> clang is crashing, in debug mode, on invalid code such as the following
> (distilled from a gcc testcase):
> ======================
> template <class>
> void foo() {
>    (struct S {}*) 0;
> }
>
> void bar() {
>    foo<int>();
> }
> ======================
>
> $ clang++ -c bug.cc
> bug.cc:3:11: error: 'S' can not be defined in a type specifier
>    (struct S {}*) 0;
>            ^
> clang: SemaTemplateInstantiate.cpp:2691:
> llvm::PointerUnion<clang::Decl*, llvm::SmallVector<clang::Decl*, 4u>*>*
> clang::LocalInstantiationScope::findInstantiationOf(const clang::Decl*):
> Assertion `isa<LabelDecl>(D) && "declaration not instantiated in this
> scope"' failed.
>
> The problem seems to be that, after emitting the error diagnostics for
> the template, the code is kept as valid code in the AST; hence it later
> causes a crash when instantiating the template.

Please find attached a patch fixing the crash mentioned above.
The patch includes minor changes to 3 tests, where (as expected) we no 
longer get further diagnostics on the code already marked as invalid.

OK to commit?

Enea.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: CrashFix.patch
Type: text/x-diff
Size: 4076 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130108/1ee1976d/attachment.patch>


More information about the cfe-commits mailing list